gpt4 book ai didi

jquery - Codeigniter 中的自定义 jquery 错误放置

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

我正在使用 jQueryplugin 表单验证,它工作得很好,但它显示每个表单元素右侧的错误消息。我其实想要每个表单元素位于我指定的特定 div 中的错误消息定制。

例如:

这是我的验证规则.js

$("#form").validate({

errorElement: "span",


//set the rules for the fields
rules: {

name: {
required: true,
minlength: 5,
maxlength:25

},
phone:{
required: true,
number: true,
minlength:10,
maxlength:11
},
email: {
required: true,
email: true
},
pswd: {
required: true,
minlength: 5,
maxlength:15
},
pswd1: {
required :true,
equalTo: "#pswd"
}


},
//set messages to appear inline
messages: {

name: {
required: "Name is required.."
},

pswd: {
required: "Please provide a password.",
minlength: "Your password must be at least 5 characters long",
maxlength: "Password can not be more than 15 characters"
},
pswd1:{
required: "Please re-Enter password.",
equalTo:"password not matching"
},
phone:{
required: "Please Enter phone no..",
number:"Not a valid phone number ",
minlength: "Not a valid phone number",
maxlength: "Phone No. cannot be more than 11 digit"
},
email: "Valid email is required.",

},

errorPlacement: function(error, element) {
error.appendTo(element.parent());
}

});

如果有人能告诉我你会怎么做,那就太好了赞赏。

最佳答案

这应该是工作

jQuery.validator.setDefaults({
errorPlacement: function(error, element) {
error.appendTo('#div_id');
}
});

关于jquery - Codeigniter 中的自定义 jquery 错误放置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14473457/

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