对象在 jquery 中不支持 addEventListener IE8

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18327225/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 21:23:24  来源:igfitidea点击:

Object doesn't support addEventListener IE8 in jquery

javascriptjquery

提问by comebal

I am using Jquery 2.0.2 and I have an error in IE8:

我正在使用 Jquery 2.0.2,但在 IE8 中出现错误:

Object doesn't support property or method 'addEventListener' jquery.min.js, line 4 character 6105

对象不支持属性或方法 'addEventListener' jquery.min.js,第 4 行字符 6105

Somehow all my codes are fine with chrome and firefox, except for ie8.

不知何故,除了 ie8,我的所有代码都适用于 chrome 和 firefox。

Getting these errors also resulted to:

获得这些错误还导致:

The value of the property '$' is null or undefined, not a Function object

属性“$”的值为 null 或未定义,不是 Function 对象

I included the query on top of other js files I have using:

我将查询包含在我使用的其他 js 文件之上:

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>

I know Jquery2+ doesnt support IE8, but I dont want to use a lesser version of Jquery.

我知道 Jquery2+ 不支持 IE8,但我不想使用较低版本的 Jquery。

回答by Arun P Johny

jQuery 2.x has dropped support for IE < 9, so if you want to support IE7 & 8 then use latest version of 1.x branch - now 1.11.0

jQuery 2.x 已放弃对 IE < 9 的支持,因此如果您想支持 IE7 和 8,请使用最新版本的 1.x 分支 - 现在是1.11.0

From jQuery

来自jQuery

jQuery 2.x has the same API as jQuery 1.x, but does not support Internet Explorer 6, 7, or 8. All the notes in the jQuery 1.9 Upgrade Guide apply here as well. Since IE 6/7/8 are still relatively common, we recommend using the 1.x version unless you are certain no IE 6/7/8 users are visiting the site.

jQuery 2.x 具有与 jQuery 1.x 相同的 API,但不支持 Internet Explorer 6、7 或 8。jQuery 1.9 升级指南中的所有说明也适用于此处。由于 IE 6/7/8 仍然比较普遍,我们建议使用 1.x 版本,除非您确定没有 IE 6/7/8 用户正在访问该站点。

回答by Brigand

jQuery 1.9 is equivalent to jQuery 2.0 as far as functionality, bug fixes, etc. They are both actively developed.

jQuery 1.9 在功能、错误修复等方面等同于 jQuery 2.0。它们都在积极开发中。

The only difference is code that provides IE compatibility was removed to make the file size and execution speed better.

唯一的区别是删除了提供 IE 兼容性的代码,以使文件大小和执行速度更好。

If you would like to use different jQuery versions depending on the browser, you can use a conditional tag, like this.

如果您想根据浏览器使用不同的 jQuery 版本,您可以使用条件标签,如下所示。

<!--[if !IE]> -->
    <script src="jquery-2.0.0b2.js"></script>
<!-- <![endif]-->

<!--[if IE]>
    <script src="jquery-1.9.1.js"></script>
<![endif]-->

Note the styntax highlighting. The first is just two comments that are siblings of the script tag, and the latter is a comment with the script tag inside it. Browsers just follow the rules of DOM parsing, and load/execute the first script. IE deviates and won't execute the first, but will execute the latter.

注意语法高亮。第一个只是两个脚本标签的兄弟注释,后者是一个带有脚本标签的注释。浏览器只是遵循 DOM 解析规则,加载/执行第一个脚本。IE 偏离,不会执行第一个,但会执行后者。

回答by Praveen

jQuery 2.xhas dropped support for IE < 9. However you can use multiple jQueryversion in same web page.

jQuery 2.x已放弃对 IE < 9 的支持。但是您可以在同一网页中使用多个jQuery版本

This can be done using jQuery.noConflict()

这可以使用 jQuery.noConflict()