javascript IE8 使用 jQuery 抛出错误

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

IE8 is throwing error with jQuery

javascriptjqueryinternet-explorer-8

提问by DS.

I'm facing some issue with IE7/IE8 and jQuery. My code works in IE 10, FF, Chrome, Safari, Mobile Safari, Mobile Chrome.

我在使用 IE7/IE8 和 jQuery 时遇到了一些问题。我的代码适用于 IE 10、FF、Chrome、Safari、Mobile Safari、Mobile Chrome。

For now, to debug, I've removed my own JS file. So here's the code:

现在,为了调试,我删除了我自己的 JS 文件。所以这是代码:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>

There is no other JS referenced on this page. I've removed all other JS reference and there is no JS executed on the page itself. When the page loads in IE8, I get this error:

此页面上没有引用其他 JS。我已经删除了所有其他 JS 引用,并且页面本身没有执行 JS。当页面在 IE8 中加载时,我收到此错误:

Line: 4
Error: Object doesn't support this property or method

enter image description here

在此处输入图片说明

The debugger shows the above. Not sure where the issue is. Any help is greatly appreciated.

调试器显示了上述内容。不知道问题出在哪里。任何帮助是极大的赞赏。

P.S. - This is my first 'serious' web development effort and I see now why IE is hated so much in the dev community.

PS - 这是我第一次“认真”的 Web 开发工作,现在我明白了为什么 IE 在开发社区中如此讨厌。

回答by Mooseman

jQuery 2.0 dropped support for some browsers. See the release post at http://blog.jquery.com/2013/04/18/jquery-2-0-released/

jQuery 2.0 不再支持某些浏览器。请参阅http://blog.jquery.com/2013/04/18/jquery-2-0-released/ 上的发布帖子

Quoting from the post:

引用帖子:

No more support for IE 6/7/8:Remember that this can also affect IE9 and even IE10 if they are used in their “Compatibility View” modes that emulate older versions. To prevent these newer IE versions from slipping back into prehistoric modes, we suggest you always use an X-UA-Compatible tag or HTTP header. If you can use the HTTP header it is slightly better for performance because it avoids a potential browser parser restart.

Reduced size:The final 2.0.0 file is 12 percent smaller than the 1.9.1 file, thanks to the elimination of patches that were only needed for IE 6, 7, and 8. We had hoped to remove even more code and increase performance, but older Android/WebKit 2.x browsers are now the weakest link. We're carefully watching Android 2.x market share to determine when we can cross it off the support list, and don't expect it to take very long.

不再支持 IE 6/7/8:请记住,如果在模拟旧版本的“兼容性视图”模式中使用它们,这也会影响 IE9 甚至 IE10。为了防止这些较新的 IE 版本滑回到史前模式,我们建议您始终使用 X-UA-Compatible 标签或 HTTP 标头。如果您可以使用 HTTP 标头,则性能会稍微好一些,因为它避免了潜在的浏览器解析器重新启动。

减小尺寸:最终的 2.0.0 文件比 1.9.1 文件小 12%,这要归功于消除了仅适用于 IE 6、7 和 8 的补丁。我们曾希望删除更多代码并提高性能,但较旧的 Android/WebKit 2.x 浏览器现在是最薄弱的环节。我们正在仔细观察 Android 2.x 的市场份额,以确定何时可以将其从支持列表中删除,并且预计不会需要很长时间。

Keep jQuery 1.9(Edit 2015-11-17: jQuery 1.11.3 is the current 1.x version of jQuery.) if IE 6/7/8 are a concern.

保留 jQuery 1.9(编辑 2015-11-17:jQuery 1.11.3 是 jQuery 的当前 1.x 版本。)如果 IE 6/7/8 是一个问题。

回答by Saajan

use the code in the below linked gist in your html file and add both jquery 2.0+ for latest browser and 1.9 for older browsers

在您的 html 文件中使用以下链接要点中的代码,并为最新浏览器添加 jquery 2.0+ 和为旧浏览器添加 1.9

https://gist.github.com/dwoodiwiss/5633393

https://gist.github.com/dwoodiwiss/5633393

回答by Nad

I faced the same issue, Actually I was referencing scripts like this;

我遇到了同样的问题,实际上我正在引用这样的脚本;

<script src="../js/jquery-ui.js" type="text/javascript"></script>
<script src="../js/jquery.min.js" type="text/javascript"></script>

I fixed this by changing scripts referencing order by calling jquery.min.js first.

我通过首先调用 jquery.min.js 更改引用顺序的脚本来解决此问题。

<script src="../js/jquery.min.js" type="text/javascript"></script>
<script src="../js/jquery-ui.js" type="text/javascript"></script> 

Add the following in the web.config:

在 web.config 中添加以下内容:

<system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="X-UA-Compatible" value="IE=EmulateIE8" />
      </customHeaders>
    </httpProtocol>
</system.webServer>