简体   繁体   English

与该字段旁边的附加注释相比,如何显示单独的jQuery Validation消息框注释:

[英]How to make a separate jQuery Validation messagebox note appear compared to an appended one next to the field: at the same time

I want a asterisk to appear next to the field, and then a specific message to appear at the bottom of my form at the same time upon validation. 我希望在该字段旁边显示一个星号,然后在验证时同时在表单底部显示一个特定消息。

Currently, I have these two versions: 目前,我有以下两个版本:

1) works for the asterisk appearing after the field title. 1)适用于字段标题后出现的星号。

2) works for making "please fill in the last name". 2)用于制作“请填写姓氏”。

However, how can I get these both to work at the same time? 但是,我如何才能使它们同时工作? Currently only the one on top of the other will work if I have them both in my file at the same time. 当前,如果我同时将它们都放在文件中,则只有一个位于另一个之上才可以使用。

1) APPENDed NEXT TO FIELD LABEL VERSION 1)追加到字段标签版本的旁边

$(document).ready(function() {

    // validate signup form on keyup and submit
    $("#newform").validate({



    errorPlacement: function(error, element) {
        error.appendTo('#title-' + element.attr('id'));
    },    

        rules: {
            lastname: {
                required: true, 
                minlength: 2            
            }
        },

        messages: {
            lastname: {
                required: "*",
                minlength: "*"
            }
        }
    });
});
</script>

2) MESSAGE BOX VERSION 2)消息框版本

$(document).ready(function() {

    // validate signup form on keyup and submit
    $("#newform").validate({

    errorLabelContainer: "#messageBox",
   wrapper: "li",
   submitHandler: function() { alert("Submitted!") 
   },    

        rules: {
            lastname: {
                required: true, 
                minlength: 2            
            }
        },

        messages: {
            lastname: {
                required: "please fill in last name",
                minlength: "please fix the last name"
            }
        }
    });
});
</script>

Thanks 谢谢

The answer was that there can only be one validate on the page that will be recognized. 答案是页面上只有一个验证将被识别。 jQuery's Validate plugin has the highlight option that can replace the asterisk method I was trying to implement. jQuery的Validate插件具有Highlight选项,可以替代我尝试实现的星号方法。

Meanwhile, errorLabelContainer can get the messages in space down by the bottom of the form. 同时,errorLabelContainer可以在窗体底部向下获取空间中的消息。

Both of those options can go into one Validate() without interfering with each other. 这两个选项都可以放入一个Validate()中,而不会互相干扰。

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

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