首页 > Web开发 > 详细

html doctype作用

时间:2015-07-24 23:54:51      阅读:215      评论:0      收藏:0      [点我收藏+]

简单介绍下html页面中DOCTYPE声明的作用:

<!doctype html>告诉浏览器是使用标准模式还是怪异模式渲染页面。

1.为html页面添加了doctype,则浏览器在standard模式渲染页面。

2.若没有给html指定doctype声明,浏览器则在quriks模式下渲染页面。

 

下面一段代码可以通过添加和屏蔽<!doctype html>来验证两种结果:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script  type="text/javascript">
        var mode=document.compatMode;
        if(mode==="CSS1Compat"){
            document.write("the document is rendered in Standards mode");
        }else if(mode==="BackCompat"){
            document.write("the document is rendered in Quirks mode");
        }else{
            document.write("the document is wired.document.compatMode="+mode);
        }
    </script>
</head>
<body>
</body>
</html>

 使用浏览器自行验证,查看输出结果。

html doctype作用

原文:http://www.cnblogs.com/web-coding/p/4675003.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!