script标签的type属性是必须的吗?

今天在看代码的时候,突然发现在引用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属性仅作为一种代码规范进行书写
 

 

 

  • 9
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值