87,923
社区成员
发帖
与我相关
我的任务
分享
var list=document.getElementsByTagName("ul");
var secondlist=list[1];
var secondlistitem=secondlist.getElementsByTagName("li");
alert(secondlistitem[0].innerText);
alert(secondlistitem[1].innerText);
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Author" CONTENT="theforever">
<META NAME="Generator" CONTENT="NotePad">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<p>There are three different types of element in this body:</p>
<ul>
<li>paragraph</li>
<li>unorder list</li>
<li>list item</li>
</ul>
<p>There are two children of html</p>
<ul>
<li id="a">head</li>
<li id="b">body</li>
</ul>
</BODY>
</HTML>
<script>
alert(document.getElementsByTagName("UL")[1].children(0).innerText);
alert(document.getElementsByTagName("UL")[1].children(1).innerText);
</script>