jQuery Validate 校驗(yàn)多個(gè)相同name的方法
導(dǎo)讀:
在表單頁(yè)中有如下代碼
<form> <input name="zhai"/><!-- 三個(gè)相同name的input --> <input name="zhai"/> <input name="zhai"/> </form>
jquery validate在對(duì)多個(gè)相同name校驗(yàn)時(shí),只校驗(yàn)第一個(gè)input框。
解決方案一:
在表單頁(yè)對(duì)應(yīng)的js中加入如下代碼 只有當(dāng)前頁(yè)可以解決對(duì)多個(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è)面都可以驗(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的方法,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- jQuery實(shí)現(xiàn) RadioButton做必選校驗(yàn)功能
- jquery 正整數(shù)數(shù)字校驗(yàn)正則表達(dá)式
- 基于jQuery.validate及Bootstrap的tooltip開發(fā)氣泡樣式的表單校驗(yàn)組件思路詳解
- jQuery easyui的validatebox校驗(yàn)規(guī)則擴(kuò)展及easyui校驗(yàn)框validatebox用法
- jQuery插件Validate實(shí)現(xiàn)自定義校驗(yàn)結(jié)果樣式
- jQuery中校驗(yàn)時(shí)間格式的正則表達(dá)式小結(jié)
- jquery對(duì)輸入框內(nèi)容的數(shù)字校驗(yàn)代碼實(shí)例
相關(guān)文章
formValidator3.3的ajaxValidator一些異常分析
ajaxvalidator是大家問的最多的問題,修正一個(gè)bug(感謝網(wǎng)友“じ龍峸√”),并把大家最關(guān)心的問題,再做一次闡述。2011-07-07jquery實(shí)現(xiàn)全選、不選、反選的兩種方法
這篇文章主要為大家詳細(xì)介紹了jquery實(shí)現(xiàn)全選、不選、反選的兩種方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09jquery實(shí)現(xiàn)圖片滾動(dòng)效果的簡(jiǎn)單實(shí)例
這篇文章主要介紹了jquery實(shí)現(xiàn)圖片滾動(dòng)效果的簡(jiǎn)單實(shí)例,有需要的朋友可以參考一下2013-11-11jQuery實(shí)現(xiàn)默認(rèn)是閉合的FAQ展開效果菜單
這篇文章主要介紹了jQuery實(shí)現(xiàn)默認(rèn)是閉合的FAQ展開效果菜單,涉及jQuery中slideUp及slideDown用法的使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09jquery checkbox實(shí)現(xiàn)單選小例
checkbox是復(fù)選框如何將其變?yōu)閱芜x呢?下面有個(gè)不錯(cuò)的示例,感興趣的朋友可以參考下2013-11-11jQuery學(xué)習(xí)筆記之 Ajax操作篇(一) - 數(shù)據(jù)加載
Ajax 通俗來(lái)講即不需要刷新頁(yè)面即可從服務(wù)器或客戶端上加載數(shù)據(jù),當(dāng)然這些數(shù)據(jù)的格式是多種多樣的。2014-06-06jQuery滑動(dòng)效果實(shí)現(xiàn)方法分析
這篇文章主要介紹了jQuery滑動(dòng)效果實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了jQuery實(shí)現(xiàn)滑動(dòng)效果常用的slideDown()、slideUp()及slideToggle()方法相關(guān)使用技巧,需要的朋友可以參考下2018-09-09