< script>之间的区别标记类型和<脚本>没有类型? [英] Difference between <script> tag with type and <script> without type?
问题描述
可能存在重复:
我应该包含type =" text / javascript"在我的SCRIPT标记中?
我正在编写HTML,发现即使键入脚本标记未设置为javascript,则仍可评估标记中的JavaScript代码。
所以我只是想知道在脚本标签和类型之间有什么区别?
在HTML 4中,需要类型
属性。根据我的经验,如果没有,所有的浏览器都会默认为 text / javascript
,但是这个行为在任何地方都没有定义。尽管你理论上可以忽略它,并假设它将被解释为JavaScript,但它是无效的HTML,所以为什么不添加它。
type
属性是可选的,默认为 text / javascript
:
type属性给出脚本的语言或数据的格式。如果该属性存在,则其值必须是有效的MIME类型。不得指定charset参数。如果该属性不存在,则使用默认值text / javascript。
Possible Duplicate:
Should I include type=“text/javascript” in my SCRIPT tags?
I was writing HTML and found that even if the type in the script tag is not set to javascript, the javascript code in the tag can still be evaluated.
so I was just wondering what the difference is between the script tag with type and one without?
In HTML 4, the type
attribute is required. In my experience, all browsers will default to text/javascript
if it is absent, but that behaviour is not defined anywhere. While you can in theory leave it out and assume it will be interpreted as JavaScript, it's invalid HTML, so why not add it.
In HTML 5, the type
attribute is optional and defaults to text/javascript
:
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".
这篇关于< script>之间的区别标记类型和<脚本>没有类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!