jQuery 不适用于 IE 11

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25077612/
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 11:02:30  来源:igfitidea点击:

jQuery not working with IE 11

jqueryjquery-uiinternet-explorer

提问by Simon.

Object doesn't support property or method 'addEventListener'

Object doesn't support property or method 'addEventListener'

'jQuery' is undefined 

I'm using IE 11,

我正在使用 IE 11,

/jquery-2.1.1.min.js

/jquery-2.1.1.min.js

jquery-migrate-1.1.1.js

jquery-migrate-1.1.1.js

and jquery-ui-1.11.0.custom/jquery-ui.js (theme roller)

和 jquery-ui-1.11.0.custom/jquery-ui.js(主题滚轮)

Before 2.1.1, i was using 1.11.1 with chrome (worked fine)

在 2.1.1 之前,我使用 1.11.1 和 chrome(工作正常)

I have tried thisfix but it did not work for me

我已经尝试过这个修复,但它对我不起作用

采纳答案by T J

The problem was caused because the page was an intranet site, & IE had compatibility mode set to default for this. IE11does support addEventListener()

问题是因为该页面是 Intranet 站点,并且 IE 为此将兼容模式设置为默认值。IE11确实支持addEventListener()

回答by Conny Olsson

As Arnaud suggested in a comment to the original post, you should put this in your html header:

正如 Arnaud 在对原始帖子的评论中所建议的那样,您应该将其放在 html 标题中:

<meta http-equiv="X-UA-Compatible" content="IE=edge">

I don't want any cred for this. I just want to make it more visible for anyone else that come here.

我不想要任何信用。我只是想让来这里的其他人更能看到它。

回答by ttugates

For me the issue turned out to be I was using es6's right arrow functions =>as opposed to function ().

对我来说,问题原来是我使用的是 es6 的右箭头函数=>,而不是function ().

Replacing =>with function ()resolved for me.

更换=>function ()解决我。

I had assumed it was a jQuery issue.

我以为这是一个 jQuery 问题。

回答by parth joshi

Thanks @Arnaud & @Conny for highlighting this answer. This really helped me. I would like to add one more thing here is, adding this line <meta http-equiv="x-ua-compatible" content="IE=edge">just after the title in tag prior to all meta tags is must for to work as it overrides the compatibility mode of IE.

感谢 @Arnaud 和 @Conny 突出显示这个答案。这真的帮助了我。我想在这里再添加一件事,<meta http-equiv="x-ua-compatible" content="IE=edge">在所有元标记之前的标签标题之后添加这一行是必须的,因为它覆盖了 IE 的兼容模式。

回答by Hemanth Peela

Place this meta tag after head tag

将此元标记放在 head 标记之后

<meta http-equiv="x-ua-compatible" content="IE=edge">

回答by Mick

Adding the "x_ua_compatible" tag to the page didn't work for me. Instead I added it as an HTTP Respone Header via IIS and that worked fine.

向页面添加“x_ua_compatible”标签对我不起作用。相反,我通过 IIS 将它添加为 HTTP 响应标头,并且效果很好。

In IIS Manager select the site then open HTTP Response Headers and click Add:

在 IIS 管理器中选择站点,然后打开 HTTP 响应头并单击添加:

enter image description here

在此处输入图片说明

The site didn't need restarting, but I did need to Ctrl+F5 to force the page to reload.

该站点不需要重新启动,但我确实需要按 Ctrl+F5 来强制重新加载页面。