IE10 和 jQuery:SCRIPT5009:“$”未定义

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

IE10 and jQuery: SCRIPT5009: "$" is undefined

jqueryinternet-explorerinternet-explorer-10

提问by BairDev

I'm faced with this really annoying problem, it appears in IE10 like in IE9. Given this HTML:

我面临着这个非常烦人的问题,它出现在 IE10 中,就像在 IE9 中一样。鉴于此 HTML:

<head>
    <title>Any Consult</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" type="text/css" href="styles.css" />
    <!--[if lte IE 9]>
        <script src="scripts/IE9.js"></script>
    <![endif]-->
    <script type="text/javascript" src="scripts/jquery.js"></script>
    <script type="text/javascript" src="scripts/scripts.js"></script>
</head>

This (scripts.js) works fine in FF and Chrome, but IE10 throws the SCRIPT5009 error.

这 (scripts.js) 在 FF 和 Chrome 中运行良好,但 IE10 会引发 SCRIPT5009 错误。

scripts.js is like (simple, but tested example):

scripts.js 就像(简单但经过测试的示例):

$(document).ready(function() {
   alert('Hello');
});

IE10 does not load the jQuery-File and I tried nearly everything. I changed and reduced the filename, I spared the

IE10 不加载 jQuery 文件,我几乎尝试了所有方法。我更改并减少了文件名,我省去了

<!--[if lte IE 9]>...

part, I tried

部分,我试过了

src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.0.min.js"

but nothing happened. Because this is a new version of this question, I'd like to specify:

但什么也没发生。因为这是这个问题的新版本,我想指定:

  1. how should I name the jQuery-File for IE(10)?
  2. where should I put the script tags in the HTML-Header?
  1. 我应该如何命名 IE(10) 的 jQuery 文件?
  2. 我应该将脚本标签放在 HTML-Header 的什么位置?

Thanks a lot!

非常感谢!

EDIT: Here the suggested HTML-version, which does not work, too:

编辑:这里建议的 HTML 版本也不起作用:

<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript" src="scripts/scripts.js"></script>
<script type="text/javascript" src="scripts/clocks.js"></script>
<!--[if lte IE 9]>
    <script src="scripts/IE9.js"></script>
<![endif]-->
<!--[if IE]><script type="text/javascript" src="scripts/excanvas.js"></script><![endif]-->

IE9.js is a browser polyfill file.

IE9.js 是浏览器的 polyfill 文件。

And here is my screenshot ("ist undefiniert" means "is undefined", "Die Webseite reagiert nicht" means "the page went down", "Debugger beenden" means "stop debugging", $('.aLang') is a class in my HTML.

这是我的屏幕截图(“ist undefiniert”表示“未定义”,“Die Webseite reagiert nicht”表示“页面关闭”,“Debugger beden”表示“停止调试”,$('.aLang') 是一个类在我的 HTML 中。

Screenshot IE10 Bug Report

截图 IE10 错误报告

采纳答案by Mike Kokitch

I had this problem with IE and found that the jQuery javascript file was corrupt in the IE developer tool. This was caused in my case by HTTP GZIP compression being done by the server but IE wasn't decompressing the file. I guess that if you turn off static HTTP compression or exclude the application/x-javascript from whatever is doing the compression (Mine was done by FluorineFX for all files over 10Kb) it should work okay once you have cleared your browser cache to get rid of the compressed javascript file.

我在 IE 上遇到了这个问题,发现 IE 开发人员工具中的 jQuery javascript 文件已损坏。在我的情况下,这是由服务器完成的 HTTP GZIP 压缩引起的,但 IE 没有解压缩文件。我想,如果您关闭静态 HTTP 压缩或从正在进行压缩的任何内容中排除应用程序/x-javascript(我的压缩文件是由 FluorineFX 完成的,用于所有超过 10Kb 的文件),一旦您清除浏览器缓存以摆脱它,它应该可以正常工作压缩后的 javascript 文件。

回答by BenM

Place the conditional script afterthe jQuery library:

代替条件脚本jQuery库:

<script type="text/javascript" src="scripts/jquery.js"></script>
<!--[if lte IE 9]>
<script src="scripts/IE9.js"></script>
<![endif]-->