简体   繁体   English

我的jquery验证注册表单中的一些问题

[英]some issues in my jquery validation registration form

My problem is when i press the button or type in my last and first name one of them dont have a jquery validation on it. 我的问题是,当我按我的按钮或类型lastfirst名称其中之一不要有上有一个jQuery验证。 And how do i make the three comboboxes have a 1 rule jquery validation instead of three poping out? 我如何使三个组合框具有1条规则的jquery验证而不是弹出的三个?

current output: http://jsfiddle.net/5kcsn/12/ 当前输出: http : //jsfiddle.net/5kcsn/12/

 $('form').validate({
        rules: {
            fname: {
                minlength: 3,
                maxlength: 15,
                required: true
            },
            lname: {
                minlength: 3,
                maxlength: 15,
                required: true
            },

            month: {
                required: true
            },
            day: {
                required: true
            },
            year: {
                required: true
            }
        },
        highlight: function (element) {
            $(element).closest('.form-group').addClass('has-error');
        },
        unhighlight: function (element) {
            $(element).closest('.form-group').removeClass('has-error');
        },
        errorElement: 'span',
        errorClass: 'help-block',
        errorPlacement: function (error, element) {
            if (element.parent('.input-group').length) {
                error.insertAfter(element.parent());
            } else {
                error.insertAfter(element);
            }
        }
    });

Check this Working Fiddle 检查此工作小提琴


  • You need to group the elements. 您需要对元素进行分组。

     groups: { DateofBirth: "month day year" }, 

And in errorPlacement: part, add this 然后在errorPlacement:部分中添加此内容

errorPlacement: function (error, element) {
            if (element.attr("name") == "day" || element.attr("name") == "month" || element.attr("name") == "year") 
                error.insertAfter(".dateWrap");
            else 
                error.insertAfter(element);
            if (element.parent('.input-group').length) {
                error.insertAfter(element.parent());
            } else {
                error.insertAfter(element);
            }
        }

  • For lname issue, your input field in html for first name has id="lname" . 对于lname问题,您在html中输入名字的字段具有id="lname" So there were two <input> elements with the ID as lname . 因此,有两个<input>元素,其ID为lname

Reference : .validate() groups . 参考: .validate()组

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM