今天在看代码的时候,突然发现在引用js的时候script模块并没有标明type属性
<script src="js/jquery.min.js"></script>
<script src="js/demo.js"></script>
要知道,在html4的年代里,type是必不可少的
<script type='text/javascript' src="js/jquery.min.js"></script>
<script type='text/javascript' src="js/demo.js"></script>
当时第一反应就是“html5难道不需要注明type了?”
去查了下,还真是
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".
type
attribute的Default value就是text/javascript, 所以没有必要写了!!!!——ly你个C
与之相似的是css中的<link>标签和<style>标签
原先是
<link href="base.css" rel="stylesheet" type="text/css" />
<style type="text/css">
span{
color:red;
}
</style>
而现在同样可以省略掉type='text/css'
因为 HTML5 中已经默认指定样式变的 type 是 text/css,脚本的type 是 text/javascript。
所以除非不是css或者javascript,type属性都是可以不写的。
现在,在涉及css/javascript时,type属性仅作为一种代码规范进行书写