复制代码 代码如下:
<strong>数据源:</strong>
<ul>
<li></li>
<ul>
<li>a_1</li>
<li>a_2</li>
<li>a_3</li>
</ul>
<li>www.jb51.net</li>
<li>www.kanshule.com</li>
</ul>
<script>
document.write("<strong>取外层ul的li信息:</strong><br>");
var tree1 = document.getElementsByTagName("ul")[0].childNodes;
for (var i = 0;i < tree1.length;i++){
document.write(tree1[i].innerHTML);
}
document.write("<br><br><strong>取内层ul的li信息:</strong><br>");
var tree2 = document.getElementsByTagName("ul")[1].childNodes;
for (var i = 0;i < tree2.length;i++){
document.write(tree2[i].innerHTML);
}
</script>
时间: 2024-12-22 19:27:21