在codeigniter中自定义jquery错误放置

时间:2013-01-23 06:06:27

标签: jquery codeigniter

我正在使用jQueryplugin表单验证,它运行良好,但它显示 每个表单元素右侧的错误消息。我真的想要 每个表单元素的错误消息都在我的特定div中 定制

例如:

这是我的验证rules.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());     
    }

});

如果有人能告诉我你将如何做到这一点,那将是非常重要的 赞赏。

1 个答案:

答案 0 :(得分:0)

这应该是工作

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