简体   繁体   English

IE8是否需要脚本类型text / javascript?

[英]Is script type text/javascript required for IE8?

I'm debugging Javascript issue on IE8, and I want to make sure that the problem is not because of this. 我正在IE8上调试Javascript问题,并且我想确保问题不是由于此而引起的。 I can't quite tell if the problem is because of this or because of something else. 我不太清楚问题是由于这个原因还是因为其他原因。 I search on the whole internet, but I feel it's very hard to get a very straightforward answer on this. 我在整个互联网上进行搜索,但是我觉得很难获得一个非常简单的答案。 Even w3school (people said that it's unreliable) that usually has "which browser support what feature starting from what version" is removing that information for this script tag. 甚至w3school(人们说这是不可靠的)通常都具有“哪个浏览器支持从哪个版本开始的功能”,因此正在删除此脚本标签的信息。 I understand there's many similar question on stack overflow that asking if it is okay to omit type attribute on script in general, and the usual answer is yes. 我了解堆栈溢出有很多类似的问题,询问通常是否可以省略脚本的type属性,通常的回答是。 But the client decided that the website must support IE8 too, and that's why I just need a straightforward answer: 但是客户决定该网站也必须支持IE8,这就是为什么我只需要一个简单的答案:

Can I omit type attribute on script tag, on IE8? 我可以在IE8的脚本标签上省略type属性吗?

If I omit it, will it has a problem, like raising Javascript error box, code not run properly, or anything, on IE8? 如果我忽略它,是否会出现问题,例如在IE8上引发Javascript错误框,代码无法正常运行或其他问题?

Thanks. 谢谢。

The type attribute is optional if you use HTML5 and pass the proper doctype 如果您使用HTML5并传递正确的doctype,则type属性是可选的

<!doctype html>

Unfortunately, IE8 doesn't recognize this doctype so in theory it should require the type attribute specified. 不幸的是,IE8无法识别此doctype,因此从理论上讲它应该要求指定type属性。 Fortunately, no one follows that particular standard, so running this code 幸运的是,没有人遵循该特定标准,因此运行此代码

<!doctype html>
<html>
    <head>
        <script>
            alert('It works!');
        </script>
    </head>
    <body></body>
</html>

results in working JS under IE8, which means you don't really need the type attribute specified after all. 导致IE8下的JS工作,这意味着您实际上并不需要真正指定的type属性。 Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM