Html HTML5 Script 标签需要 type="javascript" 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14323376/
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
Do HTML5 Script tag need type="javascript"?
提问by GusDeCooL
Possible Duplicate:
Do you need text/javascript specified in your <script> tags?
Do in HTML5, the <script>
tag need attribute type="text/javascript"
?
I mean isn't it obvious if the <script>
tag will be contains javascript?
在 HTML5 中,<script>
标签需要属性type="text/javascript"
吗?
我的意思是<script>
标签是否包含 javascript不是很明显吗?
回答by Denys Séguret
No, it's now officially useless.
不,它现在正式没用了。
The type attribute gives the language of the script or format of the data. If the attribute is present, its value must be a valid MIME type. The charset parameter must not be specified. The default, which is used if the attribute is absent, is "text/javascript".
type 属性给出了脚本的语言或数据的格式。如果该属性存在,则其值必须是有效的 MIME 类型。不得指定字符集参数。如果属性不存在,则使用的默认值是“text/javascript”。
Simply do
简单地做
<script src=yourpath.js></script>
(yes, you can omit the quotes too)
(是的,您也可以省略引号)
Note that you don't have to worry about pre-HTML5 browsers, all of them always considered JavaScript to be the default script language.
请注意,您不必担心 HTML5 之前的浏览器,它们都始终将 JavaScript 视为默认脚本语言。
回答by Oded
From the spec:
从规范:
If the language is not that described by "text/javascript", then the type attribute must be present
如果语言不是“text/javascript”描述的语言,则必须存在类型属性
And:
和:
The default, which is used if the attribute is absent, is "text/javascript".
如果属性不存在,则使用的默认值是“text/javascript”。
Conversely, that means that if your src
attribute is for a file that is valid JavaScript, it is not needed.
相反,这意味着如果您的src
属性用于有效 JavaScript 的文件,则不需要它。