我有這個腳本,可以讓用戶輸入一個文本,它會被翻譯成別的東西。只有當單詞只有一個字母時才起作用。如果有超過1個字母,則表示未定義。腳本說undefined
下面是腳本:
function copyit(theField) {
var tempval = eval("document." + theField)
tempval.focus()
tempval.select()
therange = tempval.createTextRange()
therange.execCommand("Copy")
}
function results() {
var behavior = "form";
var text = document.csrAlpha.csrresult2.value;
var ff22 = text.toLowerCase();
var Words = new Array;
Words["b"] = "Dadada";
Words["bob"] = "Robert";
Words["flower"] = "Banana";
Words["brad"] = "Chair";
var trans = "";
var regExp = /[\[email protected]#$%^&*(),=";:\/]/;
var stringCheck = regExp.exec(ff22);
if (!stringCheck) {
if (ff22.length > 0) {
for (var i = 0; i < ff22.length; i++) {
var thisChar = ff22.charAt(i);
trans += Words[thisChar] + " ";
}
} else {
trans += "Please write something.";
}
} else {
trans += "You entered invalid characters. Remove them and try again.";
}
document.csrAlpha.csrresult.value = trans;
}
和HTML:
<table>
<tr>
<td align="center" class="cleanuphtml-1">
<form name="csrAlpha">
Please insert your text below:<br />
<input type="text" class="tb3" name="csrresult2" size="70" maxlength="120" autocomplete="off" onkeydown="results()" onkeyup="results()" onkeypress="return handleEnter(this, event);" />
<input type="reset" value="Reset" onclick="csrAlpha.csrresult2.focus();" />
<p>
<textarea name="csrresult" class="tb7" cols="71" rows="10" value=""></textarea>
</p>
</form>
</td>
</tr>
</table>
請你不要四倍空間的代碼? – Blender
我的歉意,我現在就改變它。 – Strozzap
不要試圖做人的意思;)這很難閱讀。 – Blender