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

首頁 > 語言 > JavaScript > 正文

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

2024-05-06 15:17:02
字體:
來源:轉載
供稿:網友

導讀:

在表單頁中有如下代碼

 <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的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對錯新站長站網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 同江市| 成安县| 子洲县| 涿鹿县| 台北县| 遵义县| 方山县| 道孚县| 平遥县| 舟山市| 临汾市| 土默特左旗| 那曲县| 平果县| 晋江市| 安顺市| 巴林左旗| 深泽县| 石狮市| 水富县| 永嘉县| 汉川市| 平安县| 兴城市| 河间市| 井陉县| 葵青区| 清徐县| 乐山市| 龙门县| 渝中区| 兴宁市| 闻喜县| 龙川县| 金昌市| 花莲市| 灵台县| 巫山县| 连南| 芦山县| 平邑县|