使用 jquery 验证单击按钮时,自定义错误 class 未应用于所有复选框
Custom error class not applying to all the checkbox when the button is click using jquery validation
目前我在复选框中遇到问题,最初当用户单击 yes 单选按钮时,当用户单击下一步按钮时,将显示一个包含一些字段的面板错误 class 只适用于第一个复选框,但它应该适用于所有复选框这个问题可能很简单,但有些我没有得到确切的结果。这是 jquery 代码
$(".phy_clp").click(function() {
var inputValidation = $('input[name=phy_clp]:checked').val();
if (inputValidation === "yes") {
$phyexpyDiv.show();
$(".phyexpy").find(".chk_field_hlt").removeClass("chk_Field");
//$(".chk_field_hlt").addClass('errRed_chkb');
} else if (inputValidation === "no") {
$(".chk_field_hlt").removeClass('errRed');
$(".phyexpy").find(".chk_field_hlt").addClass("chk_Field");
$phyexpyDiv.hide();
}
});
提前致谢
在您的 highlight
和 unhighlight
中,请参阅 the source code of the plugin,您可以在其中看到正确处理 radio
按钮的默认代码。
由于您要覆盖此默认代码,因此您需要对 checkbox
元素执行类似的操作。
highlight: function (element) {
if (element.type === "checkbox") {
this.findByName(element.name).addClass('errRed').removeClass('text-error-black');
} else {
$(element).addClass('errRed');
$('#imageUploadForm').addClass('errRed');
$(element).prevAll('label').find('span.required-star').addClass('text-error-red').removeClass('text-error-black');
}
},
unhighlight: function (element) {
if (element.type === "checkbox") {
this.findByName(element.name).addClass('text-error-black').removeClass('errRed');
} else {
$(element).removeClass('errRed');
$(element).prevAll('label').find('span.required-star').addClass('text-error-black').removeClass('text-error-red');
}
}
目前我在复选框中遇到问题,最初当用户单击 yes 单选按钮时,当用户单击下一步按钮时,将显示一个包含一些字段的面板错误 class 只适用于第一个复选框,但它应该适用于所有复选框这个问题可能很简单,但有些我没有得到确切的结果。这是 jquery 代码
$(".phy_clp").click(function() {
var inputValidation = $('input[name=phy_clp]:checked').val();
if (inputValidation === "yes") {
$phyexpyDiv.show();
$(".phyexpy").find(".chk_field_hlt").removeClass("chk_Field");
//$(".chk_field_hlt").addClass('errRed_chkb');
} else if (inputValidation === "no") {
$(".chk_field_hlt").removeClass('errRed');
$(".phyexpy").find(".chk_field_hlt").addClass("chk_Field");
$phyexpyDiv.hide();
}
});
提前致谢
在您的 highlight
和 unhighlight
中,请参阅 the source code of the plugin,您可以在其中看到正确处理 radio
按钮的默认代码。
由于您要覆盖此默认代码,因此您需要对 checkbox
元素执行类似的操作。
highlight: function (element) {
if (element.type === "checkbox") {
this.findByName(element.name).addClass('errRed').removeClass('text-error-black');
} else {
$(element).addClass('errRed');
$('#imageUploadForm').addClass('errRed');
$(element).prevAll('label').find('span.required-star').addClass('text-error-red').removeClass('text-error-black');
}
},
unhighlight: function (element) {
if (element.type === "checkbox") {
this.findByName(element.name).addClass('text-error-black').removeClass('errRed');
} else {
$(element).removeClass('errRed');
$(element).prevAll('label').find('span.required-star').addClass('text-error-black').removeClass('text-error-red');
}
}