我需要这个,可以添加一个选项,例如,拆分和再次加入我不知道这很多但我看到了一个带有该选项的动作脚本它是" a,b,c" 这里是actionscript代码,但我想在javascript中请帮助我得到它...
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.
}
答案 0 :(得分:0)
首先......如果您想在键入时执行脚本,则没有理由添加"搜索"按钮。 无论如何,这是输入字段上的代码(当你输入时)和搜索按钮,选择你想要使用的东西:
<input id="sInput" type="text" onkeydown="translate()">
<input type="button" value="Search" onClick="translate()">
然后,在此代码之后,在div&#34;结果&#34;之后,你必须添加javascript代码:
<script type="text/javascript">
function translate()
{
var sInput = document.getElementById('sInput').value;
sInput = sInput.split("how r u sis").join("how are you sister ").split("how r u bro").join("how are you brother ").split("whatsup ").join("what is up ");
document.getElementById('result').innerHTML =sInput;
}
</script>