html - SCRIPT、STYLE 和 LINK 元素的类型属性是否仍然需要?

标签 html css browser

你会看到很多网站都有以下类型的代码:

脚本元素:

<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.

HTML4XHTML 中,W3C standards 要求它.

对于stylelink 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/

相关文章:

JavaScript 打印输入innerHTML 返回未定义?

javascript - 需要在 JS var 中存储 html 日期输入

HTML 和样式对齐问题

php - 提交任何帖子时出现 WordPress 间距问题

html - 如何获得垂直子菜单而不是水平子菜单?

html - 为什么此 html 表定义无效?

javascript - CSS:将弹出窗口水平定位在所需位置

javascript - 内联 JS 回调语法与内部 JS 回调语法

java - 如何使用Selenium java在浏览器中的两个窗口之间切换

ruby-on-rails - 如何更改文件名提示文本浏览器另存为对话框?