gpt4 book ai didi

javascript - 如何在 jquery 验证插件中添加自定义错误替换消息?

转载 作者:行者123 更新时间:2023-12-03 08:59:09 25 4
gpt4 key购买 nike

我想使用 jquery 验证插件添加自定义错误替换 ( http://jqueryvalidation.org/documentation/ ) 我想进行自定义错误替换,例如单击此处

$(function() {
//simple example 1
//click event for first button

$("#form1").validate({
errorPlacement: function(error, element) {
if (element.attr("name") == "business_email" ) {
$("#bus_email").css('color',"#f42156");
$("#busp_email").removeClass("field_validation_error hidden");
$("#busp_email").addClass("field_validation_error");
}
},
rules: {
business_email: "required"
},
messages: {
business_email: "Please enter your firstname"
}
});
});

https://jsfiddle.net/fr0dc2es/7/

最佳答案

使用此代码,您可以获得自定义替换消息并对#bus_email执行操作:

$(function() {
//simple example 1
//click event for first button

$("#form1").validate({
rules: {
business_email: "required"
},
messages: {
business_email: "Please enter your firstname"
},
errorPlacement: function(error, element) {
if (element.attr("name") == "business_email") {
$("#bus_email").css('color',"#f42156");
$("#busp_email").removeClass("hidden");
$("#busp_email").html(error);
} else {
$("#busp_email").addClass("hidden");
$("#busp_email").html();
error.insertAfter(element);
}
}
});
});

JQueryValidation Documentation

关于javascript - 如何在 jquery 验证插件中添加自定义错误替换消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32368468/

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