日期:2014-05-16 浏览次数:20435 次
<!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>
<dl id="dl1">
<dt>aa</dt>
<dd>
<ul>
<li>aaa</li>
<li>bbb</li>
</ul>
<dd>
<dt>bb</dt>
<dd>
<ul>
<li>111</li>
</ul>
<dd>
</dl>
<script type="text/javascript">
var dl1 = document.getElementById('dl1');
var counter = 0;
function showNode(pNode) {
for(var i = 0; i < pNode.childNodes.length; i ++) {
if (pNode.childNodes[i].nodeType == 1) {
alert('找到子元素节点:' + pNode.childNodes[i].nodeName);
counter ++;
if (pNode.childNodes[i].childNodes.length > 0) showNode(pNode.childNodes[i]);
}
}
}
showNode(dl1);
document.write('共有' + counter + '个元素节点');
</script>
</body>
</html>