你会看到很多网站都有以下类型的代码:
脚本元素:
<script type="text/javascript">
//javascript here
</script>
链接元素:
<link rel="stylesheet" href="url.css" type="text/css" media="all" />
样式元素:
<style type="text/css">
/* CSS */
</style>
我的问题是:
当今流行的浏览器是否需要 type
属性?
(流行的意思是 IE 8+、Firefox、Webkit、Opera 和 Chrome)
如果您不包含它们会怎样?
注意:如果 HTML5 和 XHTML 文档类型之间存在行为差异,则答案需要涵盖两者。
最佳答案
简而言之,自 HTML5 以来它们不是必需的,但在 HTML4/XHTML 中是 W3C 标准所必需的>.
在 HTML5 script
标签的 type
中:
type - This attribute identifies the scripting language of code embedded within a script element or referenced via the element’s src attribute. This is specified as a MIME type; examples of supported MIME types include text/javascript, text/ecmascript, application/javascript, and application/ecmascript. If this attribute is absent, the script is treated as JavaScript.
在 HTML4 和 XHTML 中,W3C standards 要求它.
对于style
和link
type
:
In HTML5, the type attribute is no longer required. Default value is "text/css".
关于html - SCRIPT、STYLE 和 LINK 元素的类型属性是否仍然需要?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12634315/