HTML – 仍然需要SCRIPT,STYLE和LINK元素上的类型属性吗?

您将看到许多具有以下类型代码的网站:

脚本元素:

<script type="text/javascript">
   //javascript here
</script>

链接元素:

<link rel="stylesheet" href="url.css" type="text/css" media="all" />

风格元素:

<style type="text/css">
   /* CSS */
</style>

我的问题是:

今天流行的浏览器中是否需要类型属性

(流行的意思是IE 8,Firefox,Webkit,Opera和Chrome)

如果你不包括它们会发生什么?

注意:如果两者之间的行为存在差异,则答案需要涵盖HTML5和XHTML文档类型.

解决方法

简而言之,自HTML5以来它们不是必需的,但是HTML4 / XHTML中的W3C标准要求它们.

在HTML5类型的脚本标记中:

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所要求的.

对于样式和链接类型:

In HTML5,the type attribute is no longer required. Default value is “text/css”.

相关文章

vue阻止冒泡事件 阻止点击事件的执行 &lt;div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些