这些HTML5的冷知识,你知道多少?

1.空标签无需闭合,如 <meta>、<link>、<img>、<input>、<br>、<hr> 等标签。

2.<link> 标签的 type 属性不必需。

3.<script> 标签的 type 属性不必需,默认值是 “text/javascript”。

4.<style> 标签的 type 属性不必需,默认值是 “text/css”。

5.链接、引用资源省略http或https协议。如:

<link rel="stylesheet" href="//www.example.com/css/style.css">
<a href="//www.example.com/">www.example.com</a>
<img src="//www.example.com/images/hello.jpg">

6.利用a标签自动解析URL

var a = document.createElement('a');
a.href = 'http://www.example.com:8080/dir/getUsers?name=Johnson&sex=男&age=25#top';

console.log(a.protocol); // => http:
console.log(a.hostname); // => www.example.com
console.log(a.host); // => www.example.com:8080
console.log(a.port); // => 8080
console.log(a.pathname); // => /dir/getUsers
console.log(a.search); // => ?name=Johnson&sex=%E7%94%B7&age=25
console.log(a.hash); // => #top
此条目发表在HTML分类目录,贴了, 标签。将固定链接加入收藏夹。

发表回复