2

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

这是我目前的功能:

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!");
        }
    });

我怎样才能做到这一点?

4

2 回答 2

2

当您使用 Bassistance.de 验证插件时,最简单的选择是title向每个输入控件的参数添加一条友好的指令消息。然后,此消息将用作出现的错误消息中的说明文本。这是一个更新的小提琴,展示了它是如何工作的:http: //jsfiddle.net/xTdYr/3/

.validate()或者,您可以使用messages参数在方法的实例化调用中手动添加规则,详细信息在这里: http ://docs.jquery.com/Plugins/Validation/rules

于 2011-11-07T11:02:49.817 回答
0

扩展选项messages: {name:"name error"}

现场演示:http: //jsfiddle.net/gsBTC/

$('#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"
   }
});
于 2011-11-07T11:09:06.043 回答