我需要这个,它可以添加一个选项,如分裂和再次加入我不知道这一点,但我看到一个动作脚本与该选项它是“ A,b,C“ 这里是ActionScript代码,但我想它在JavaScript,请帮我把它...动作脚本到Java脚本 - 字符串到字符串翻译
tIn.onChanged = function()
{
var sInput = tIn.text; //Gets the text from the first text field.
sInput = translate(sInput); //Goes through the translator.
tOut.text = sInput; //Sets the second text field to the translated text.
}
function translate(sInput)
{
//This is where you add how you want your text changed.
//It should be in the format of
//sInput = searchAndReplace(sInput, What you want changed, What you want it changed to);
//Remember to use quotes around the text you are changing.
sInput = searchAndReplace(sInput, "how r u sis", "how are you sister ");
sInput = searchAndReplace(sInput, "how r u bro", "how are you brother ");
sInput = searchAndReplace(sInput, "whatsup ", "what is up ");
return sInput;
}
function searchAndReplace(a, b, c) //Searches string a for b and replaces it with c
{
tmp = a.split(b); //Splits a into an array of values where b is.
a = tmp.join(c); //Joins them back together with c seperating them.
return (a); //Returns the changed string.
}
我没有看到JS中的任何问题,而不是.text,你应该把它放在一个html元素(使用getElementById)。 无论如何你可以缩短它: 'sInput = sInput.split(“怎么ru sis”)。join(“你好吗姐妹”).split(“怎么ru兄弟”)。join(“你好吗兄弟” ).split(“whatsup”).join(“what is up”);' – Nadia
嗨@Nadia感谢您的快速答案,但我仍然有一些问题在这里是代码:http://raadso.net/tests/ translate.html – OmarTeacher