gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 13:41:10 24 4
gpt4 key购买 nike

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

脚本元素:

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com