我同时使用DirtyForms和 popupar jQuery Validate来验证我的表单。我还需要使用该submitHandler()
方法,因为在实际发送表单之前我会执行一些操作。在这种情况下,即使在正常的提交表单上也会触发 DirtyForms,而这是不应该的。
$('.validate').validate({
// submitHandler causer DirtyForms to be triggered evn on normal form submit
submitHandler: function (form) {
// do a couple of things here, then...
form.submit();
}
});
$('form[method="post"]').dirtyForms();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.dirtyforms/2.0.0/jquery.dirtyforms.min.js"></script>
<p>Fill the field and send the form, you'll see that DirtyForms is triggered even if it should not</p>
<form action="#" method="post" class="validate">
<input type="text" name="username" required>
<button type="submit">send</button>
</form>
请问,有什么帮助吗?