首页 > 技术文章 > 判断页面是否添加了W3C声明

clear93 2015-07-28 13:46 原文

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>判断页面是否添加了W3C声明</title>
<script>
if (document.compatMode=="CSS1Compat")
alert("本文档添加了W3C的声明")
else
alert("本文档未添加W3C的声明")
</script>
</head>
<body>
本例的重点是“document.compatMode”变量的值。当文档有了标准声明时,“document.compatMode” 的值就等于“CSS1Compat”。
</body>
</html>

推荐阅读