我需要這個,它可以添加一個選項,如分裂和再次加入我不知道這一點,但我看到一個動作腳本與該選項它是「 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