Javascript,LI 내용 가 져 오기

934 단어 Javascript획득LI

<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>

좋은 웹페이지 즐겨찾기