防止表单提交 [英] Prevent form from submitting
问题描述
我有这个
$("#contact-frm-2").bind("jqv.form.result", function(event , errorFound){
if(!errorFound){
alert('go!');
event.preventDefault();
return false;
}
});
它应该验证表单是否有错误,当表单上没有错误时,提醒Go !没有提交。
我使用的是jquery.ValidationEngine.js你可以在 http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/
It supposed to validate the form for errors and when there is no error on the form, alert "Go!" without submitting. I am using the jquery.ValidationEngine.js you can find at http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/
我确定
event.preventDefault();
return false;
应该阻止表单提交但仍在提交。有人能告诉我我错过了什么吗?谢谢
is supposed to prevent the form from submitting but it is still submitting. Can someone tell me what I am missing? Thanks
推荐答案
onsubmitJavaScript事件将为您处理此问题。
The "onsubmit" JavaScript event will handle this for you.
jQuery:
$('#formid').submit(function(e) {
e.preventDefault();
});
纯JS:
document.getElementById('formid').addEventListener('submit', function(e) {
e.preventDefault();
});
这篇关于防止表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!