我有javascript函数。我正在使用该功能在文本字段中将英语翻译成另一种语言。如下表当一个人在box01中输入时,box02以翻译模式显示输入的英文内容。
<form id="txtBox" action="ps.php" enctype="multipart/form-data" method="post">
<textarea id="box01" onkeyup="startText_sin();" onselect="startText_sin();" onclick="startText_sin();" rows="2" placeholder ="Type in Here"></textarea>
<textarea id="box02" rows="2" placeholder ="Translated"></textarea>
</form>
但是我的单页中很少有这些表格,并且文本区域有不同的名称,如下所示,
<textarea id="txt_sin01"></textarea>
<textarea id="txt_trn02"></textarea>
我怎样才能将功能设置为与所有这些文本区域一起使用?
我的功能是**startText_sin()**
在功能中我选择这样的文本区域text = document.getElementById("box01");
任何帮助。
_ _ ___功能_ __ _ __ _ _
` //数组放在这里
函数 startText_sin() {
var s,r,v;
//text = document.txtBox.box1.value;
text_singlish = document.getElementById("box1_singlish").value;
//special consonents
for (var i=0; i<specialConsonants.length; i++){
text_singlish = text_singlish.replace(specialConsonants[i], specialConsonantsUni[i]);
}
//consonents + special Chars
for (var i=0; i<specialCharUni.length; i++){
for (var j=0;j<consonants.length;j++){
s = consonants[j] + specialChar[i];
v = consonantsUni[j] + specialCharUni[i];
r = new RegExp(s, "g");
text_singlish = text_singlish.replace(r, v);
}
}
//consonants + Rakaransha + vowel modifiers
for (var j=0;j<consonants.length;j++){
for (var i=0;i<vowels.length;i++){
s = consonants[j] + "r" + vowels[i];
v = consonantsUni[j] + "්ර" + vowelModifiersUni[i];
r = new RegExp(s, "g");
text_singlish = text_singlish.replace(r, v);
}
s = consonants[j] + "r";
v = consonantsUni[j] + "්ර";
r = new RegExp(s, "g");
text_singlish = text_singlish.replace(r, v);
}
//consonents + vowel modifiers
for (var i=0;i<consonants.length;i++){
for (var j=0;j<nVowels;j++){
s = consonants[i]+vowels[j];
v = consonantsUni[i] + vowelModifiersUni[j];
r = new RegExp(s, "g");
text_singlish = text_singlish.replace(r, v);
}
}
//consonents + HAL
for (var i=0; i<consonants.length; i++){
r = new RegExp(consonants[i], "g");
text_singlish = text_singlish.replace(r, consonantsUni[i]+"්");
}
//vowels
for (var i=0; i<vowels.length; i++){
r = new RegExp(vowels[i], "g");
text_singlish = text_singlish.replace(r, vowelsUni[i]);
}
document.getElementById("box2_singlish").value=text_singlish; //wirte on page in sihala
}
`