最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jQuery Validate 校驗(yàn)多個(gè)相同name的方法

 更新時(shí)間:2017年05月18日 14:04:32   作者:翟鳳璽  
這篇文章主要介紹了jQuery Validate 校驗(yàn)多個(gè)相同name的方法,需要的朋友可以參考下

導(dǎo)讀:

在表單頁中有如下代碼

 <form>
  <input name="zhai"/><!-- 三個(gè)相同name的input -->
  <input name="zhai"/>
  <input name="zhai"/>
 </form>

jquery validate在對多個(gè)相同name校驗(yàn)時(shí),只校驗(yàn)第一個(gè)input框。

解決方案一:

在表單頁對應(yīng)的js中加入如下代碼 只有當(dāng)前頁可以解決對多個(gè)name校驗(yàn)

 if ($.validator) {
   $.validator.prototype.elements = function () {
    var validator = this,
     rulesCache = {};
    return $(this.currentForm)
    .find("input, select, textarea")
    .not(":submit, :reset, :image, [disabled]")
    .not(this.settings.ignore)
    .filter(function () {
     if (!this.name && validator.settings.debug && window.console) {
      console.error("%o has no name assigned", this);
     }
     rulesCache[this.name] = true;
     return true;
    });
   }
  }

解決方案二:

修改源文件 所有的頁面都可以驗(yàn)證多個(gè)name

方式1:修改jquery.validate.js文件

用 ctrl+F 查找 this.name in rulesCache 注釋掉如下代碼。

elements: function() {
   var validator = this,
    rulesCache = {};
   // select all valid inputs inside the form (no submit or reset buttons)
   return $(this.currentForm)
   .find("input, select, textarea")
   .not(":submit, :reset, :image, [disabled]")
   .not( this.settings.ignore )
   .filter(function() {
    if ( !this.name && validator.settings.debug && window.console ) {
     console.error( "%o has no name assigned", this);
    }
    // 注釋掉這里
    // select only the first element for each name, and only those with rules specified
    //if ( this.name in rulesCache || !validator.objectLength($(this).rules()) ) {
    // return false;
    //} 
    rulesCache[this.name] = true;
    return true;
   });
  },

方式2:修改jquery.validate.min.js文件

用 ctrl+F 查找(c[this.name]=!0,!0)})

 return !this.name && b.settings.debug && window.console && console.error("%o has no name assigned", this),
//this.name in c || !b.objectLength(a(this).rules()) ? !1 : (c[this.name] = !0, !0)//注釋這行
c[this.name] = !0, !0 //添加這行

以上所述是小編給大家介紹的jQuery Validate 校驗(yàn)多個(gè)相同name的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論

新绛县| 南昌市| 北安市| 塔河县| 庆阳市| 阜新市| 绥芬河市| 彝良县| 正蓝旗| 无为县| 信阳市| 五台县| 阿勒泰市| 通州区| 西贡区| 玛曲县| 黔西县| 黄石市| 昌乐县| 海城市| 探索| 拉萨市| 永城市| 龙口市| 冀州市| 奎屯市| 定陶县| 通海县| 中阳县| 青浦区| 象州县| 乌兰察布市| 湖州市| 武威市| 双城市| 洪江市| 于田县| 巴马| 仪陇县| 芮城县| 恩施市|