< script>之间的区别标记类型和<脚本>没有类型? [英] Difference between <script> tag with type and <script> without type?

查看:98
本文介绍了< script>之间的区别标记类型和<脚本>没有类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:

我应该包含type =" text / javascript"在我的SCRIPT标记中?


我正在编写HTML,发现即使键入脚本标记未设置为javascript,则仍可评估标记中的JavaScript代码。

所以我只是想知道在脚本标签和类型之间有什么区别?

解决方案

在HTML 4中,需要类型属性。根据我的经验,如果没有,所有的浏览器都会默认为 text / javascript ,但是这个行为在任何地方都没有定义。尽管你理论上可以忽略它,并假设它将被解释为JavaScript,但它是无效的HTML,所以为什么不添加它。

在HTML 5中, 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屋!

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