Firefox 4 beta 更新后出现未定义错误
有人可以检查我的代码并告诉我哪里做错了。我对 javascript 很差,并且长期使用此代码,在 Firefox 从 3.5 更新到 4 beta 后,我收到了未定义的错误。
function Convert_ONE2TWO()
{
var arrTWO = new Array( "a", "e", "i");
var arrONE = new Array( "A", "E", "I");
str=document.frmConvert.txtONE.value; //input from ONE
for (i=0;i<3;i++) //Loop for all letters
{
strTemp=new RegExp(arrONE[i], "ig");
str=str.replace(strTemp,arrTWO[i]); //Replacing
}
document.frmConvert.txtTWO.value=str.toString(); //output to TWO
}
<form name="frmConvert" action="" method="get">
<textarea rows="5" cols="90" name="txtONE"></textarea>
<input name="btnConvertg" value="Create TWO" onclick="Convert_ONE2TWO();" type="Button">
<textarea rows="5" cols="90" name="txtTWO"></textarea>
</form>
Can somebody check my code and tell me where I'm doing wrong. I'm very poor in javascript and using this code from long time, after firefox update from 3.5 to 4 beta, I'm getting undefined error.
function Convert_ONE2TWO()
{
var arrTWO = new Array( "a", "e", "i");
var arrONE = new Array( "A", "E", "I");
str=document.frmConvert.txtONE.value; //input from ONE
for (i=0;i<3;i++) //Loop for all letters
{
strTemp=new RegExp(arrONE[i], "ig");
str=str.replace(strTemp,arrTWO[i]); //Replacing
}
document.frmConvert.txtTWO.value=str.toString(); //output to TWO
}
<form name="frmConvert" action="" method="get">
<textarea rows="5" cols="90" name="txtONE"></textarea>
<input name="btnConvertg" value="Create TWO" onclick="Convert_ONE2TWO();" type="Button">
<textarea rows="5" cols="90" name="txtTWO"></textarea>
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的循环是错误的。您有三个数组元素,但执行四次循环迭代。
使用 for (var i = 0; i < 3; i++) 并记住数组索引从
0
开始,而不是1
。Your loop is wrong. You have three array elements, but perform four loop iterations.
Use
for (var i = 0; i < 3; i++)
and remember that array indices start at0
, not1
.