Goodsu

导航

 

简单介绍下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>

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

posted on 2015-07-24 22:45  Goodsu  阅读(462)  评论(0编辑  收藏  举报