我要使用此按钮提交:
<button id="registerButton" type="submit" name="submit" style="margin-left: 300px;">Click to Complete</button>
我正在用这个 jQuery 做错误检查:
$('#registerButton').bind('click',function(){
if($('#formElem').data('errors')){
alert('Please correct the errors in the Form');
return false;
}
});
当我提交表单时,如果在表单上检测到错误,它会弹出警报。但是,如果没有错误,该按钮不会执行任何操作。我做错了什么?
最佳答案
在表单的提交事件上绑定(bind)验证。
$("#formid").submit(function(e) {
if($(this).data('errors')){
//display error
e.preventDefault(); //stop the submit
} else {
//do something or nothing
//but it will submit the form
}
});
关于jQuery Submit 不会提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9711361/