- <strong>数据源:</strong>
- <ul>
- <li>a</li>
- <ul>
- <li>a_1</li>
- <li>a_2</li>
- <li>a_3</li>
- </ul>
- <li>b</li>
- <li>c</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>
如何使用Javascript(简称JS)取得LI里的内容(简单易懂的代码实例)
最新推荐文章于 2024-08-27 15:59:21 发布