gpt4 book ai didi

jquery - resetForm() 不会调用取消突出显示

转载 作者:行者123 更新时间:2023-12-01 04:08:36 26 4
gpt4 key购买 nike

我想在调用resetForm()时取消突出显示。有办法做到这一点吗?

$('#coupon_submit_btn').on('click',function(){
.....
$('#coupon_code').val("");
validator.resetForm(); ......

编辑:

其中验证器是我验证的表单

var validator = $('#checkout_form_payment').validate({ rules......

最佳答案

郑重声明,如果您想拥有 resetForm()调用unhighlight() ,您可以将以下内容添加到您的 JS 中:

$.validator.prototype.resetForm = function() {
if ( $.fn.resetForm ) {
$(this.currentForm).resetForm();
}
this.submitted = {};
this.lastElement = null;
this.prepareForm();
this.hideErrors();
var elements = this.elements().removeData("previousValue").removeAttr("aria-invalid");
if (this.settings.unhighlight) {
for (var i = 0; elements[i]; i++) {
this.settings.unhighlight.call(this, elements[i], this.settings.errorClass, this.settings.validClass);
}
}
}

这将取代现有的 resetForm()复制现有的resetForm()行为,但将删除错误类的代码替换为调用 unhighlight()在每个元素上。

关于jquery - resetForm() 不会调用取消突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23934892/

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