<img src="//mzwu.com/img/logo.png">img 中的url是以双斜杠“//”开头的,这种写法有特殊的用途,它会判断当前的页面协议是http 还是 https 来决定请求 url
的协议。防止IE下出现“This page contains both secure and nonsecure items”的报错。

如果你浏览的是本地文件,它又会解析为 file:// 协议。
这种特性可以用来加载CDN:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>也适用于CSS:
.omgomg { background: url(//mzwu.com/lvtao.gif); }注意:如果在IE7,IE8中使用 <link> 和 @import 引入 CSS 的时候,会下载两次 CSS 文件。
参考资料
[1].the-protocol-relative-url:http://www.paulirish.com/2010/the-protocol-relative-url/
评论(0)
暂无评论。