【问题标题】:The showErrors() function of jQuery Validation PluginjQuery Validation Plugin 的 showErrors() 函数
【发布时间】:2009-09-09 04:45:36
【问题描述】:

以下脚本运行良好:

$("#regform").validate().showErrors({"username":"message"});

我把脚本改成下面这个后,就不行了。

var name = "username";
$("#regform").validate().showErrors({name:"message"});

我需要通过变量传递字段名称。有谁知道如何解决这个问题?

【问题讨论】:

    标签: jquery jquery-plugins


    【解决方案1】:

    您应该构建一个对象字面量并使用bracket notation 成员访问运算符:

    var name = "username",
        obj = {};
    obj[name] = "message";
    
    $("#regform").validate().showErrors(obj);
    

    【讨论】:

      猜你喜欢
      • 2013-06-03
      • 1970-01-01
      • 2018-07-08
      • 1970-01-01
      • 2018-01-23
      • 2016-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多