为什么asp中用了onsubmit后就不能提交表单了

来源:百度知道 编辑:UC知道 时间:2024/06/18 10:40:00
我的部分代码如下:
<form id="form1" name="form1" method="post"
onsubmit="return check()" action="select2.asp">
<label>请输入要查询的ID号:
<input type="text" name="id" />
</label>
<p align="center">
<label>
<input name="Submit" type="submit" class="STYLE4" value="确定" />
</label>
</p>
</form>

其中check函数是这样的:

<Script language="javascript">
function check(){
if (document.forms[0].id.value =="" ){
alert("请填写ID号 ^o^ ");
document.forms[0].id.focus();
document.forms[0].id.select();
return false;
}
for(var i= 0 ;i<document.forms[0].id.value.length;i++){
var string2 = document.forms[0].id.value.charAt(i);
if (string2<"

少了个{
和return true;

我修正后的check代码如下:
function check(){
if (document.forms[0].id.value =="" ){
alert("请填写ID号 ^o^ ");
document.forms[0].id.focus();
document.forms[0].id.select();
return false;
}
for(var i= 0 ;i<document.forms[0].id.value.length;i++){
var string2 = document.forms[0].id.value.charAt(i);
if (string2<"0"||string2>"9")
{
alert("数据无效,ID号应该为数字 ^o^ ");
document.forms[0].id.focus();
document.forms[0].id.select();
return false;
}
return true;
}
</Script>

测试正常