题目:
打印出 id=“bj” 该节点的所有子节点的(nodeName, nodeType, nodeValue)同时打印文本值 北京 海淀 奥运
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>yuhan20081021</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<ul>
<li id="bj" value="beijing">北京
<p>海淀</p>
奥运
</li>
<li id="sh" value="shanghai">上海</li>
</ul>
</body>
<script language="JavaScript">
//打印出 id="bj" 该节点的所有子节点的(nodeName, nodeType, nodeValue)
var bjElement=document.getElementById("bj");
alert(bjElement.firstChild.nodeName);
alert(bjElement.firstChild.nodeType);
alert(bjElement.firstChild.nodeValue);
alert(bjElement.childNodes[1].nodeName);
alert(bjElement.childNodes[1].nodeType);
alert(bjElement.childNodes[1].nodeValue);
alert(bjElement.childNodes[2].nodeName);
alert(bjElement.childNodes[2].nodeType);
alert(bjElement.childNodes[2].nodeValue);
//同时打印文本值 北京 海淀 奥运
alert(bjElement.childNodes[0].nodeValue);
alert(bjElement.childNodes[1].firstChild.nodeValue);
alert(bjElement.childNodes[2].nodeValue);
</script>
</html>