如何在jQuery Validate错误消息中包含字段标签 [英] How do I include the field label in a jquery Validate error message

查看:157
本文介绍了如何在jQuery Validate错误消息中包含字段标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面顶部显示我的jquery验证错误.我想在每封邮件旁边添加与每个无效字段关联的标签的文本值.这是怎么做的.这是我的jQuery.

I am displaying my jquery validate errors at the top of the page. I want to include the text value of the label associated with each invalid field next to each message. How is this done. Here is my jquery.

$(document).ready(function(){
    $("#reqAccount").validate({
            errorClass: "error-text",
            validClass: "valid",
            errorLabelContainer: "#errorList",
            wrapper: "li ",
            highlight: function(element, errorClass, validClass) {
                $(element).addClass("error-input").addClass(errorClass).removeClass(validClass);
             },
             unhighlight: function(element, errorClass, validClass) {
                $(element).removeClass("error-input").removeClass(errorClass).addClass(validClass);
             }
        });
    });

推荐答案

如果我对您的理解正确,我认为您也许可以使用showErrors:

If I understand you correctly, I think you might be able to use showErrors:

$(".selector").validate({
   showErrors: function(errorMap, errorList) {
      //use the fn params to get a map of current errors,
      //then append to your <li> elements
   }
});

参考 http://docs.jquery.com/Plugins/Validation/validate 在选项"下标签.

这篇关于如何在jQuery Validate错误消息中包含字段标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆