当我显示它时,我不知道一旦没有错误,如何隐藏它.我有在这里拨弄来演示它:在两个字段中的任何一个中键入任何内容,尽管错误消息消失了,但摘要仍然保留.必须有一个我需要订阅的活动,但我无法弄清楚.$(document).ready(function () { var validator = validation_rules('#myform'); validator.form(); function validation_rules(form) { $.validator.addClassRules("fillone", { require_from_group: [1, ".fillone"] }); var validator = $(form).validate({ errorPlacement: function (error, element) { var field_error = $(form).find('#id_' + element.attr('name')).siblings('.field_error'); if (field_error.length > 0) { error.appendTo(field_error); } $(field_error).show(); }, invalidHandler: function () { $("#validation_summary").text(validator.numberOfInvalids() + " field(s) are invalid"); } }); return validator; }});解决方案使用errorContainer选项.当表单变为有效/无效时,这将显示/隐藏指定的元素 errorContainer:{#validation_summary"} 示例位于 http://jsfiddle.net/eDk2m/7 阅读评论后进行编辑 有一个事件需要挂接到-一个很好的例子在 custom-methods-demo.html 页.看起来像这样var validator = $("form").bind("invalid-form.validate", function() { var errorCount = validator.numberOfInvalids(); // do other stuff here}).validate({...});I have implemented an error summary according to this example here:while I get it to display, I don't have a clue how to hide it once there are no errors remaining.I have fiddle here to demonstrate it:type in anything in either of the two fields, while the error messages go away, the summary still remains. There must be an event that I need to subscribe to, but I can't figure it out.$(document).ready(function () { var validator = validation_rules('#myform'); validator.form(); function validation_rules(form) { $.validator.addClassRules("fillone", { require_from_group: [1, ".fillone"] }); var validator = $(form).validate({ errorPlacement: function (error, element) { var field_error = $(form).find('#id_' + element.attr('name')).siblings('.field_error'); if (field_error.length > 0) { error.appendTo(field_error); } $(field_error).show(); }, invalidHandler: function () { $("#validation_summary").text(validator.numberOfInvalids() + " field(s) are invalid"); } }); return validator; }}); 解决方案 use the errorContainer option. This will show/hide the specified elements when the form becomes valid/invalid errorContainer:{"#validation_summary"}example is on http://jsfiddle.net/eDk2m/7edit after reading commentthere is an event to hook into - a good example is in the custom-methods-demo.html page of the plugin demos. It looks like thisvar validator = $("form").bind("invalid-form.validate", function() { var errorCount = validator.numberOfInvalids(); // do other stuff here}).validate({...}); 这篇关于jQuery validate:如何显示和隐藏错误摘要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-27 14:20