国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

jQuery Validate 校驗多個相同name的方法

2019-11-19 16:33:26
字體:
來源:轉載
供稿:網友

導讀:

在表單頁中有如下代碼

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

jquery validate在對多個相同name校驗時,只校驗第一個input框。

解決方案一:

在表單頁對應的js中加入如下代碼 只有當前頁可以解決對多個name校驗

 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;    });   }  }

解決方案二:

修改源文件 所有的頁面都可以驗證多個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 校驗多個相同name的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 家居| 宁国市| 平顺县| 清河县| 临城县| 颍上县| 香港| 涞水县| 高碑店市| 曲阜市| 文成县| 华宁县| 盘锦市| 谷城县| 和静县| 黎城县| 台东市| 四子王旗| 丽江市| 随州市| 榆社县| 房产| 大冶市| 常山县| 峨边| 简阳市| 廉江市| 抚顺县| 马龙县| 玛纳斯县| 湘潭市| 柘城县| 仲巴县| 德令哈市| 泰顺县| 中阳县| 台中县| 安福县| 定襄县| 玉树县| 远安县|