`

jQuery的validate 在ie9和火狐下能用 在ie8下无效解决方法。

阅读更多

juqery.validate.js中发现elements方法中$([]).add(this.currentForm.elements)方法在ie8下有问题,只能得到一个jquery对象。(ie9和火狐浏览器正常)

后来根据源码中的注释提示在网站 http://bugs.jquery.com/ticket/2114  得到答案 :

原文:

I had an issue where jquery.validate was failing in IE6, caused by the above error. I fixed this by updating line 446 and changed:

$([]).add(this.currentForm.elements).filter(":input")

to

$(':input',this.currentForm)

于是把juqery.validate.js中elements方法

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

修改为:

   return $(':input',this.currentForm)
   .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;
   });

分享到:
评论
2 楼 xa_zbl 2013-01-23  
最后没有采用这种方法,发现原因出在jquery1.7和validator版本冲突了,使用低版本的jquery后好了
1 楼 woshixushigang 2013-01-15  
你好,我也遇到jquery vaidate 再ie下失效问题,请问按照你的方式改了之后,出现其他问题了吗?

相关推荐

    jQuery表单验证插件

    formValidator对主流浏览器有良好的兼容性,包括Chrome、Firefox、Safari、Edge和IE8+。但在某些老版本或非标准浏览器中,可能需要额外的优化工作。 总结,jQuery formValidator插件通过提供便捷的API和丰富的验证...

    jquery formValidator

    7. **兼容性**:与大多数现代浏览器兼容,包括Chrome、Firefox、Safari、Edge和IE9及以上版本。 **二、使用步骤** 1. **引入依赖**:首先需要在HTML文件中引入jQuery库和FormValidator的JavaScript及CSS文件。 2. ...

    jquery表单验证组件

    4. **兼容性**:与大多数现代浏览器兼容,包括Chrome、Firefox、Safari、Edge和IE9及以上版本。 5. **文档支持**:附带的使用说明文档,详细解释了如何配置和使用组件,方便开发者上手。 ### 四、使用步骤 1. **...

    免分表单验证,jQuery实现,一句代码搞定一个控件验证,且自动还原提示信息。

    这个版本的jQuery适用于大部分现代浏览器,包括IE6及以上版本,以及Firefox、Chrome、Safari和Opera等。 "crlCheckCommons.js"可能是开发者自定义的一个验证插件,其中可能包含了各种常用的验证规则和方法。例如,...

    Jquery全解析,ajax框架

    - **广泛的兼容性**:jQuery能够兼容各种主流浏览器(包括IE、Firefox、Chrome、Safari等),确保代码在不同环境中都能稳定运行。 #### 二、Ajax框架与jQuery的关系 Ajax(Asynchronous JavaScript and XML)是一...

    关于form-validation表单验证的配置

    这个插件兼容多种浏览器,包括IE6到IE8,以及Chrome、Firefox、Safari和Opera 10。尽管在较旧版本的IE中可能无法呈现CSS3的阴影和圆角效果,但基本功能仍然可用。 以下是一些常见的验证规则及其用法: 1. `...

Global site tag (gtag.js) - Google Analytics