Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery验证错误显示名称_Jquery_Validation_Errorplacement - Fatal编程技术网

jQuery验证错误显示名称

jQuery验证错误显示名称,jquery,validation,errorplacement,Jquery,Validation,Errorplacement,我想将错误的名称添加到我的函数中,以便用户知道他们必须检查哪些字段 这是我目前的职能: showErrors: function(errorMap, errorList) { var summary = "Please check following errors:"; $.each(errorList, function() { summary += " * " + this

我想将错误的名称添加到我的函数中,以便用户知道他们必须检查哪些字段

这是我目前的职能:

showErrors: function(errorMap, errorList) {
            var summary = "Please check following errors:";
            $.each(errorList, function() {
                summary += " * " + this.message + "<br>" ;
            });
            $('.errorbox').html(summary);
            this.defaultShowErrors();
        },
        submitHandler: function() {
            alert("submitted!");
        }
    });
错误:功能(错误映射,错误列表){
var summary=“请检查以下错误:”;
$.each(错误列表,函数(){
summary+=“*”+this.message+“
”; }); $('.errorbox').html(摘要); this.defaultRors(); }, submitHandler:function(){ 警报(“已提交!”); } });

如何执行此操作?

当您使用basistance.de validation插件时,最简单的选择是向每个输入控件的
标题
参数添加友好的说明消息。然后,此消息将用作出现的错误消息中的说明文本。下面是一个更新的小提琴,展示了它是如何工作的:


或者,您可以使用
messages
参数在
.validate()
方法的实例化调用中手动添加规则,详细信息如下:

使用
messages扩展选项:{name:“name error”}

现场演示:


我不知道我必须标记为已解决。谢谢你让我知道!mansuUK在前一个问题中所做的小提琴展示了它现在是如何实现的。推荐。如果不可能,您可以使用name属性,如
summary+=“*”+this.element.name+”:“+this.message+”\n”表单正在以不同的语言处理,因此当我从不同的语言文件加载标准消息时,使用消息不是最好的选择。这样,错误反馈看起来完全相同。真的没有办法在反馈信息中添加名称值吗?Marco的回答对我很有用。谢谢大家的建议。问题是表单是多语言的。所以我使用不同语言的语言文件。我可以为每个元素添加特定的消息,但我有3种不同语言中的70个元素。这是很多信息。因此,我更喜欢使用每种语言的通用消息,并添加“名称”,以便用户知道哪个字段不正确。
$('#newform').validate({
    errorPlacement: function(error, element) {
        if (element.is(":radio")) {
            error.prependTo(element.parent());
        }
        else { // This is the default behavior of the script  
            error.insertAfter(element);
            console.log('here');
        }
    },
    showErrors: function(errorMap, errorList) {
        var summary = "You have the following errors: \n";
        $.each(errorList, function() {
            summary += " * " + this.message + "\n";
        });
        $('#errordiv').html(summary);
        this.defaultShowErrors();
    },
    submitHandler: function() {
        alert("submitted!");
    }, 
    messages: {
     name   : "name error", 
     subject: "subject error",
     message: "message error"
   }
});