form表单的onsubmit时,为什么会重复触发两次js函数?
ncly 2005-04-23 01:29:20 <script language="javascript">
function chkid(checkStr) {
var checkOK ="0123456789";
return(chkstring(checkStr, checkOK));
}
function chkstring(checkStr, checkOK) {
var allValid = true;
if (typeof(checkStr) != "string" || typeof(checkOK) != "string") return(false);
for (i = 0; i < checkStr.length; i++) {
ch = checkStr.charAt(i);
if (checkOK.indexOf(ch) == -1) {
allValid = false;
break;
}
}
return(allValid);
}
function check(){
if (chkid(document.form1.a.value)==false)
{
alert("输入不规范.");
document.form1.a.focus();
return false;
}
}
</script>
<form name="form1" method="post" action="abc.asp" onsubmit="return check()">
请输入证号:
<input name="a" type="text" id="a" size="20">
<input name="Submit" type="submit" value="确定">
</form>
这里的问题是 输入非数字数据时,按“确定”后为什么会alert两次呀?