使用Uploadify 时,同时使用了jQuery.Validition 验证控件时,在IE11上出现JS缺少对象错误。



场景:

  使用jQuery.1.8.2

  使用 Uploadify 3.2上传控件

  使用jQuery.Validition 1.9 验证

  

  

  使用IE 11 时,当鼠标点击上传按钮时,会出现JS 缺少对象错误。如下图:

      

    错误定位在jQuery中.

    

  

 

      排查后发现是引用了jQuery Validition 验证控件导致的。

      在jQuery Validition控件初始化中,有下面一段代码:

    

复制代码
$currentSection
                .validateDelegate(":text, [type='password'], [type='file'], select, textarea, " +
                    "[type='number'], [type='search'] ,[type='tel'], [type='url'], " +
                    "[type='email'], [type='datetime'], [type='date'], [type='month'], " +
                    "[type='week'], [type='time'], [type='datetime-local'], " +
                    "[type='range'], [type='color'] ",
                    "focusin focusout keyup", delegate)
                .validateDelegate("[type='radio'], [type='checkbox'], select, option", "click", delegate);
复制代码


 你只要将这段代码注释掉,错误就会消失。

 

   查看一下validateDelegate这个方法:

  

1
2
3
4
5
6
7
8
9
$.fn.validateDelegate=  function (delegate, type, handler) {
         // 验证委托
         return  this .on(type,  function (event) {
             var  target = $(event.target);
             if  (target.is(delegate)) {
                 return  handler.apply(target, arguments);
             }
         });
     };

  

 里面只是对元素绑定一下事件,没有什么特殊代码。

 

  尝试在Html中移除了jQuery.validitioin插件后,在当前页面写入以下代码:

 

1
2
3
$( "form" ).on( "focusin focusout keyup" , function (){
     // TODO:
});

  

这段代码也会导致上面说的问题。

 

因为是在jQuery上抛出的错误,定位到jQuery中:

1
2
3
4
5
6
acceptData:  function ( elem ) {
         var  noData = elem.nodeName && jQuery.noData[ elem.nodeName.toLowerCase() ];
 
         // nodes accept data unless otherwise specified; rejection can be conditional
         return  !noData || noData !==  true  && elem.getAttribute( "classid" ) === noData;
     }

  

注重调试到elem.getAttribute这个方法,在其它的元素上都没用问题,但是在获取object元素上,在IE11 这个上,getAttribute方法不存在为null,所以就会报出之前上述代码。

将代码加一个判断即可:

1
2
3
4
5
6
acceptData:  function ( elem ) {
         var  noData = elem.nodeName && jQuery.noData[ elem.nodeName.toLowerCase() ];
 
         // nodes accept data unless otherwise specified; rejection can be conditional
         return  !noData || noData !==  true  && <span style= "color: #ff0000;" >elem.getAttribute !=  null </span> && elem.getAttribute( "classid" ) === noData;
     }

  

 我尝试使用jQuery 1.9和1.12都依然存在这个问题。所以只将1.8.2的代码更改了,其它还有一处碰到object这个元素都会有这个问题。

 更改后的jquery 1.8.2 下载:

    jquery-1.8.2-FIX_Object.getAttribute_is_Null Download



其他精彩文章

jQuery教程(29)-jQuery插件开发之为插件方法指定参数

jQuery教程(28)-jQuery插件开发之使用插件

jQuery教程(27)-jQueryajax操作之修改默认选项

jQuery教程(26)-ajax操作之使用JSONP加载远程数据

更多关于android开发文章



  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值