jQuery 3.1.1错误:对象不支持属性或方法"andSelf" [英] jquery 3.1.1 Error: Object doesn't support property or method 'andSelf'

查看:470
本文介绍了jQuery 3.1.1错误:对象不支持属性或方法"andSelf"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是NuGet将我的jquery从1.8.3更新到3.1.1. 然后,我不断在每个页面上收到此错误.环顾四周后,jquery似乎获得了多次执行,但是当我签入开发人员工具时,情况似乎并非如此.

所以,这就是它发生的地方.

jQuery.Deferred.exceptionHook = function( error, stack ) {

    // Support: IE 8 - 9 only
    // Console exists when dev tools are open, which can happen at any time
    if ( window.console && window.console.warn && error && rerrorNames.test( error.name ) ) {
        window.console.warn( "jQuery.Deferred exception: " + error.message, error.stack, stack );
    }
};

jQuery.readyException = function( error ) {
    window.setTimeout( function() {
        throw error;
    } );
};

在"window.console.warn ...."行上有警告- jQuery.Deferred例外:a(...).parents(...).andSelf不是函数

该错误将引发抛出错误"行- 未捕获的TypeError:a(...).parents(...).andSelf不是函数

知道为什么会这样吗?

解决方案

jQuery在版本1.8中弃用了andSelf,在版本3.0.0中将其删除,这就是为什么在3.1.1中它不是函数"的原因.

您应该使用 $.fn.addBack ,但是您发布的代码是其中的一部分处理错误的jQuery的代码,这不是问题,在您的代码中的某处有一段代码表示a(...).parents(...).andSelf(),应将其更改为a(...).parents(...).addBack().

I just NuGet update my jquery from 1.8.3 to 3.1.1. Then I keep getting this error on every page. After looking around, it seem like jquery is getting execute multiple times, but that doesn't seem to be the case when I check in developer tool.

So, this is where it happens.

jQuery.Deferred.exceptionHook = function( error, stack ) {

    // Support: IE 8 - 9 only
    // Console exists when dev tools are open, which can happen at any time
    if ( window.console && window.console.warn && error && rerrorNames.test( error.name ) ) {
        window.console.warn( "jQuery.Deferred exception: " + error.message, error.stack, stack );
    }
};

jQuery.readyException = function( error ) {
    window.setTimeout( function() {
        throw error;
    } );
};

On line "window.console.warn...." it has warning - jQuery.Deferred exception: a(...).parents(...).andSelf is not a function

And the error is thrown on line "thrown error" - Uncaught TypeError: a(...).parents(...).andSelf is not a function

Any idea why this happens?

解决方案

jQuery deprecated andSelf in version 1.8 and removed it in version 3.0.0, which is why it's "not a function" in 3.1.1.

You should be using $.fn.addBack instead, but the code you've posted is the part of jQuery that handles errors, this is not the problem, somewhere in your code there's a piece of code that says a(...).parents(...).andSelf() which should be changed to a(...).parents(...).addBack().

这篇关于jQuery 3.1.1错误:对象不支持属性或方法"andSelf"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆