当前位置: 代码迷 >> JavaScript >> javascript怎么访问子ul标签
  详细解决方案

javascript怎么访问子ul标签

热度:92   发布时间:2012-05-14 15:24:34.0
javascript如何访问子ul标签
<script type="text/javascript">
function shownav()
{
var nav=document.getElementById('nav').getElementsByTagName("li");
 

for(i=0;i<nav.length;i++)
{

nav[i].onmouseover=function()
{
nav[i].childNodes[i].style.display="none";
}
nav[i].onmouseout=function()
{
}
}
}
</script>
</head>
<body onload="shownav()">
<ul id="nav">
<li>About
  <ul>
  <li>Introduction</li>
  <li>means</li>
  <li>Features</li>
  </ul>
  </li> 
  <li>About
  <ul>
  <li>Introduction</li>
  <li>means</li>
  <li>Features</li>
  </ul>
  </li> 
</ul>
</body>
</html>


------解决方案--------------------
HTML code

<style>
    ul ul {display:none}
</style>
<script type="text/javascript">
function shownav()
{
var nav=document.getElementById('nav').children;
  
for(i=0,len=nav.length;i<len;i++)
{

nav[i].onmouseover=function()
{
this.children[0].style.display="block"; 
}
nav[i].onmouseout=function()
{
this.children[0].style.display="none"; 
}
}
}
</script>
</head>
<body onload="shownav()">
<ul id="nav">
<li>About
  <ul>
  <li>Introduction</li>
  <li>means</li>
  <li>Features</li>
  </ul>
  </li>  
  <li>About
  <ul>
  <li>Introduction</li>
  <li>means</li>
  <li>Features</li>
  </ul>
  </li>  
</ul>
</body>
</html> 
  相关解决方案