现在的位置: 首页 > 综合 > 正文

JS取得HTML页面的DOCTYPE

2013年02月18日 ⁄ 综合 ⁄ 共 477字 ⁄ 字号 评论关闭
http://topic.csdn.net/u/20080112/14/cffa064a-4740-4e8c-a7d6-2797a563ffd4.html
<!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">
<head>
   
<title>Untitled Page</title>
</head>
<body>
<script type="text/javascript">
alert(document.firstChild.nodeValue);
alert(document.childNodes[0].nodeValue);
</script>
</body>
</html>

愚公注:
上述方法仅适用于IE,且有个BUG:IE将DOCTYPE元素当做是注释,nodeValue时会去掉前4个字符和后3个字符。

抱歉!评论已关闭.