javascript中<script>在<body>后面写的为什么浏览器仍把<script>解析在<body>里?

javascript中<script>在<body>后面写的为什么浏览器F12仍把<script>解析在<body>里,而且总默认是<body>最后一个子节点?

<!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>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>无标题文档</title>

</head>

<body>

<input type="text" id="userName"/>

<img src="user.png" /> 

</body>

<script type="text/javascript">

var bodyNode = document.getElementsByTagName("body")[0];


var children = bodyNode.childNodes; 

for(var i = 0 ; i<children.length ; i++){

if(children[i].nodeType==1){

alert("节点的名字:"+children[i].nodeName+" 对象的类型:"+children[i].nodeType);

}

}

alert("第一个子节点:"+bodyNode.firstChild.nodeName); 

alert("最后一个子节点:"+bodyNode.lastChild.nodeName); 

alert("下个兄弟节点:"+inputNode.nextSibling.nodeName); //下一个兄弟节点。

alert("上一个兄弟节点:"+inputNode.previousSibling.nodeName); */

</script>

</html>


qq_夜殇城_0
浏览 1821回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript