为什么IE8不识别type =" application / javascript"在脚本标签? [英] Why doesn't IE8 recognize type="application/javascript" in a script tag?
问题描述
我开发了一个使用jQuery和Ajax的HTML页面。我的< head>
标记中包含以下行:
I developed an HTML page that uses jQuery and Ajax. I had the following lines in my <head>
tag:
<script language="javascript" type="application/javascript" src="script/jquery.js"></script>
<script language="javascript" type="application/javascript">
function someFunction() {
some code;
}
</script>
...
later - down in the body tag:
<a href="javascript:someFunction();">click here</a>
它在FF和Chrome中运行得非常好,但是我在IE8中尽快投放了预期的对象点击链接。即使启用了脚本调试器,它也无法到达函数的第一行。
我尝试切换到IE7模式,或IE8 Compatability模式 - 无济于事。
我很幸运,发现了通过Google提问,有人建议将< script>
标记中的类型
更改为 text / javascript
现在它适用于所有3种浏览器。
我的问题是:我做错了什么?是text / javascript
优于application / javascript
,还是有更好的(==更正确解决我的问题?
It worked perfectly in FF and Chrome, but threw an "Object Expected" in IE8 as soon as I clicked the link. Even with the Script Debugger on, it would not reach the first line of the function.
I tried switching to IE7 mode, or IE8 Compatability mode - to no avail.
I lucked out and found a question through Google where someone suggested changing the type
in the <script>
tag to "text/javascript"
and now it works in all 3 browsers.
My question is: what did I do wrong? Is "text/javascript"
better than "application/javascript"
, or is there a better (== more correct) solution to my issue?
推荐答案
text / javascript是所有三种浏览器都支持的唯一类型。但是,您实际上并不需要输入类型。如果没有另外指定,脚本标记的type属性将默认为text / javascript。这将如何影响验证,我不确定。但无论如何这真的很重要吗?
"text/javascript" is the only type that is supported by all three browsers. However, you don't actually need to put a type. The type attribute of a script tag will default to "text/javascript" if it is not otherwise specified. How that will affect validation, I'm not sure. But does that really matter anyway?
这篇关于为什么IE8不识别type =" application / javascript"在脚本标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!