Javascript 获取LI里的内容
人气:0复制代码 代码如下:
<strong>数据源:</strong>
<ul>
<li></li>
<ul>
<li>a_1</li>
<li>a_2</li>
<li>a_3</li>
</ul>
<li>www.qb5200.com</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>
加载全部内容