// select only the first element for each name, and only those with rules specified //if ( this.name in rulesCache || !validator.objectLength($(this). ...
1、將引入的插件:jquery.validate.js 第484行的代碼註釋:
// 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; }
2、頁面中需要驗證的輸入框必須加上不同的id。
如:html中:
<form>
<input type='text' name='name' id='name1' val=''/>
<input type='text' name='name' id='name2' val=''/>
</form>
js:
var $form=$('form'),validator=$form.validate();
$.extend(validator.settings,{
rules:{
"name":'required'
}
});