gpt4 book ai didi

Jquery-验证自定义成功消息

转载 作者:行者123 更新时间:2023-12-01 04:27:57 25 4
gpt4 key购买 nike


我正在使用 jquery 验证插件。
这是修改后的bassistance形式。
我的语法如下。

var validator = $("#myform").validate({
rules: {
field1: {
required: true,
remote: {
url: "field1.php",
type: "post",
},
},
field2: {
required: true,
remote: {
url: "field2.php",
type: "post",
},
},
Date: {
required: true,
},
},
messages: {
field1: "Specify field1",
field2: "Specify field2",
Date: {
required: "Specify Date",
},
},
errorPlacement: function(error, element) {
error.appendTo($('#errorbox'));
},
success: function(label) {
label.html("OK").addClass("checked");
}
});

在这里我可以选择显示不同的自定义错误消息。但是我如何显示不同的自定义成功消息?

提前致谢..:)

爆弹弗莱德

最佳答案

一种简单但可能不是那么聪明的方法是,您可以修改上面的 success 函数以包含条件逻辑来选择 label.html() 的内容。

这是一个例子:

success: function(label) {
// if input validated is "#username" do something special
if (label.attr('for') == "username") {
// add a label next to the field saying username is available and assign css class "checked" to this label
label.html("username available").addClass("checked");
// add css class to change background color for the input box to have a green border (presumes you have input.valid defined in your css file)
var element = '#' + label.attr('for');
$(element).addClass('valid');
} else {
// For other valid input boxes just add generic label like "OK!"
label.html("OK!").addClass("checked");
}
},

关于Jquery-验证自定义成功消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5064759/

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