`
txlaijava
  • 浏览: 55438 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

解决 jQuery Validation插件 相同名称文本框只验证第一个

    博客分类:
  • java
阅读更多

关于jQuery Validation插件,当页面有相同名称文本框只验证第一个的解决办法. 

打开源文件,找到elements方法.

注释掉:

f ( this.name in rulesCache || !validator.objectLength($(this).rules()) )
					return false;

		elements: function() {
			var validator = this,
				rulesCache = {};

			// select all valid inputs inside the form (no submit or reset buttons)
			// workaround $Query([]).add until http://dev.jquery.com/ticket/2114 is solved
			return $([]).add(this.currentForm.elements)
			.filter(":input")
			.not(":submit, :reset, :image, [disabled]")
			.not( this.settings.ignore )
			.filter(function() {
				!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;
			});
		},
分享到:
评论
3 楼 txlaijava 2011-08-31  
lqixv 写道
我动态增加多个输入框后,按照你的方法,确实可以进行同名验证了。现在的问题是,错误总是出现在第一个出现错误的地方。这个怎么解决?

这个问题我也还没有解决. 但是我想到一个办法. 把错误提示放到相同名字文本框的顶部.
2 楼 lqixv 2011-08-26  
我动态增加多个输入框后,按照你的方法,确实可以进行同名验证了。现在的问题是,错误总是出现在第一个出现错误的地方。这个怎么解决?
1 楼 lqixv 2011-08-26  
能不能发一个修改好的版本出来?谢谢

相关推荐

Global site tag (gtag.js) - Google Analytics