gpt4 book ai didi

javascript - 阻止表单提交

转载 作者:行者123 更新时间:2023-12-02 19:21:49 26 4
gpt4 key购买 nike

我有这个:

$("#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/ 找到

我确定

event.preventDefault();
return false;

应该阻止表单提交,但它仍在提交。有人可以告诉我我错过了什么吗?

最佳答案

"onsubmit" JavaScript event将为您处理此事。

jQuery:

$('#formid').submit(function(e) {
e.preventDefault();
});

纯JS:

document.getElementById('formid').addEventListener('submit', function(e) {
e.preventDefault();
});

关于javascript - 阻止表单提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12461755/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com