1
我使用了下面的腳本來驗證它在IE中的工作號碼,但它不適用於新版本的Chrome。如果輸入大於5,則顯示警報窗口但無法關閉,我必須關閉所有Chrome窗口。怎麼修 ?驗證碼javascript在Chrome中無法正常工作
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<script>
function validate(textarea)
{
var wanted = "12345"
var check ;
var x ;
for (var i=0; i<textarea.value.length; i++)
{
x = "" +textarea.value.substring(i, i+1);
if (wanted.indexOf(x) == "-1") check = "stop";
}
if (check== "stop")
{
alert("use only numbers from 1 to 5 ");
textarea.focus();
textarea.select();
}
if (textarea.value.length > 1)
{
alert("use only numbers from 1 to 5 ");
textarea.focus();
return (false);
}
}
</script>
</HEAD>
<BODY>
<FORM name="game" >
<table align="center" border="0" width="225" bgcolor="#FFFFF0" >
<TR><TD colspan="9">Fill the cells with digits 1-5, only one time each. </TD></TR>
<TR><TD><INPUT name="a1" size="1" value="" onBlur="validate(this)"><TD> <B> </B></TD>
<TD><INPUT name="a2" size="1" onBlur="validate(this)"></TD>
<TD><B> </B></TD>
<TD><INPUT name="a3" size="1" value="" onBlur="validate(this)">
</TD><TD><B> </B></TD>
<TD><INPUT name="a4" size="1" onBlur="validate(this)"></TD>
<TD><B> </B></TD>
<TD><INPUT name="a5" size="1" onBlur="validate(this)"></TD>
</TR>
</FORM>
</TABLE>
</BODY>