2008/08/21
| |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<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/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<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>
Tags:
不指定 2008/08/21 16:22, wxxslt, 网站建设 » JS, 评论(0), 阅读(829)
发表评论
表情
emotemotemotemot
emotemotemotemot
emotemotemotemot
emotemotemotemot
emotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]
               

 
Theme by Marshal. Powered by Bo-Blog 2.1.1 ReleaseCode detection by Bug.Center.Team