将从< script>中移除该类型在任何浏览器中打破标签? [英] Will removing the type from a <script> tag break in any browsers?

查看:102
本文介绍了将从< script>中移除该类型在任何浏览器中打破标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在HTML5中,当您使用JavaScript时,您不再需要在脚本标记中包含该类型。



常见的浏览器(IE6 +,Firefox 2+, Safari 3+,Opera 9+或类似的)如果类型从所有< script> 标签中被移除,将会中断?



所以,正在改变以下内容:

 < script type =text / javascriptsrc =/路径/ js.js>< /脚本> 
< script type =text / javascript>
...
< / script>

到:

 < script src =/ path / js.js>< / script> 
< script>
...
< / script>

...打算在任何地方休息?

解决方案

不,它不会破坏任何流行的浏览器,包括你提到的浏览器。如果没有类型属性,< script> 标记将会正常工作,因为所有流行的浏览器都会默认使用JavaScript。 / p>

引用Douglas Crockford


type =text / javascript



该属性是可选的。由于Netscape 2是所有浏览器中的默认编程语言,都是JavaScript。在XHTML中,这个属性是必需的和不必要的。在HTML中,最好不要使用它。浏览器知道该怎么做。



In HTML5, you no longer need to include the type in a script tag when you are using JavaScript.

Are any common browsers (IE6+, Firefox 2+, Safari 3+, Opera 9+ or similar) going to break if the type is removed from all the <script> tags?

So, is changing the following:

<script type="text/javascript" src="/path/js.js"></script>
<script type="text/javascript">
...
</script>

to:

<script src="/path/js.js"></script>
<script>
...
</script>

... going to break anywhere?

解决方案

No it won't break any of the popular browsers, including the ones you mention. The <script> tag will work fine without the type attribute, because all popular browsers will default to JavaScript.

Quoting Douglas Crockford:

type="text/javascript"

This attribute is optional. Since Netscape 2, the default programming language in all browsers has been JavaScript. In XHTML, this attribute is required and unnecessary. In HTML, it is better to leave it out. The browser knows what to do.

这篇关于将从&lt; script&gt;中移除该类型在任何浏览器中打破标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆