<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml...
<html xmlns="http://www.w3.org/1999/xht...
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>getElementsByTagName()</title>
<script language="javascript">
function searchDOM()
{
var oLi=document.getElementsByTagName("li");
alert(oLi.length+" "+oLi[0].tagName+" "+oLi[3].childNodes[0].nodeValue);
var oUI=document.getElementsByTagName("ul");
var oLi2=oUI[1].getElementsByTagName("li");
alert(oLi2.length+" "+oLi2[0].tagName+" "+oLi2[1].childNodes[0].nodeValue);
}
</script>
</head>
<body onload="searchDOM()">
<ul>
客户端语言
<li>HTML</li>
<li>JavaScript</li>
<li>CSS</li>
</ul>
<ul>
服务端语言
<li>ASP.NET</li>
<li>JSP</li>
<li>PHP</li>
</ul>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xht...
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>getElementsByTagName()</title>
<script language="javascript">
function searchDOM()
{
var oLi=document.getElementsByTagName("li");
alert(oLi.length+" "+oLi[0].tagName+" "+oLi[3].childNodes[0].nodeValue);
var oUI=document.getElementsByTagName("ul");
var oLi2=oUI[1].getElementsByTagName("li");
alert(oLi2.length+" "+oLi2[0].tagName+" "+oLi2[1].childNodes[0].nodeValue);
}
</script>
</head>
<body onload="searchDOM()">
<ul>
客户端语言
<li>HTML</li>
<li>JavaScript</li>
<li>CSS</li>
</ul>
<ul>
服务端语言
<li>ASP.NET</li>
<li>JSP</li>
<li>PHP</li>
</ul>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml...
<html xmlns="http://www.w3.org/1999/xht...
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>getElementById()</title>
<script language="javascript">
function searchDOM()
{
var oLi=document.getElementById("css");
alert(oLi.tagName+" "+oLi.childNodes[0].nodeValue);
}
</script>
</head>
<body onload="searchDOM()">
<ul>
客户端语言
<li>HTML</li>
<li id="css">JavaScript</li>
<li>CSS</li>
</ul>
<ul>
服务端语言
<li>ASP.NET</li>
<li>JSP</li>
<li>PHP</li>
</ul>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xht...
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>getElementById()</title>
<script language="javascript">
function searchDOM()
{
var oLi=document.getElementById("css");
alert(oLi.tagName+" "+oLi.childNodes[0].nodeValue);
}
</script>
</head>
<body onload="searchDOM()">
<ul>
客户端语言
<li>HTML</li>
<li id="css">JavaScript</li>
<li>CSS</li>
</ul>
<ul>
服务端语言
<li>ASP.NET</li>
<li>JSP</li>
<li>PHP</li>
</ul>
</body>
</html>



2008/08/21 16:22 | by 



