jsp表单验证跳转问题

来源:百度知道 编辑:UC知道 时间:2024/06/24 23:43:17
我做了个页面,用JAVASCRIPT验证表单,验证到表单的非法数据后能正常弹出提示框,但却马上提交了。验证出错后应该不能提交的,不知道哪里写错了:
function checkNotNull(theField, fieldName) {
if(isBlank(theField.value)){
alert(fieldName + "不可为空!");
theField.focus();
return false;
}

return true;
}
script type="text/javascript" language="javascript">
function checkForm(jibenform){
if (!checkNotNull(jibenform.bumen,"部门")) return false;
}

function checksubmit() {
if (checkForm(document.jibenform)==true) {
}
}
<form name="jibenform" method="post" action="1.jsp" >
<input type="submit" name="Submit" value="提交" onClick="return checksubmit();" />
<input type="reset" name="Submit2" value="重置" />

在form 的onsubmit属性中调用你的方法


当然即使错误也会提交的
应该在 From 里面用 onsubmit="function() return "
他返回的时return 如果你输入错了 时不会提交的