Jqueryvalidation淋浴显示名称

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

这是我目前的职能

showErrors: function(errorMap, errorList) { var summary = "Please check following errors:"; $.each(errorList, function() { summary += " * " + this.message + "
" ; }); $('.errorbox').html(summary); this.defaultShowErrors(); }, submitHandler: function() { alert("submitted!"); } });

我怎样才能做到这一点?

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

或者,您可以使用messages参数在.validate()方法的instanciation调用中手动添加规则,详情请参见: http : //docs.jquery.com/Plugins/Validation/rules

使用messages: {name:"name error"}扩展选项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" } });