日期:2014-05-16  浏览次数:20339 次

JS获取DIV中的LI

<DIV class="time_lbc">
<UL id=index_tab01>
<LI onMouseOver="this.className='b'" onMouseOut="this.className=''">
  <span class="cx">XX</span>
  <SPAN class="xm">XX</SPAN>
  <SPAN class="jie" style="display:none">XX</span>
  <SPAN class="list">XX</SPAN>
  <SPAN class="address">XX</SPAN>
</LI>
<LI onMouseOver="this.className='b'" onMouseOut="this.className=''">
......
</LI>
....N个LI
</UL>
</DIV>


请问如何用JS获取所有LI中第三个<SPAN>里隐藏的内容

------解决方案--------------------

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(function(){
$("#abv").click(function(){
$("span:hidden").each(function(){
alert($(this).text());
});
});
})
</script>
<input type="button"  id="abv" value="测试用按钮"/>
<div class="time_lbc">
<ul id="index_tab01">
<li onMouseOver="this.className='b'" onMouseOut="this.className=''">
  <span class="cx">XX</span>
  <span class="xm">XX</span>
  <span class="jie" style="display:none">XX1</span>
  <span class="list">XX</span>
  <span class="address">XX</span>
</li>
<li onMouseOver="this.className='b'" onMouseOut="this.className=''">
  <span class="cx">XX</span>
  <span class="xm">XX</span>
  <span class="jie" style="display:none">XX2</span>
  <span class="list">XX</span>
  <span class="address">XX</span>
</li>
</ul>
</div>

------解决方案--------------------

var liUnion=document.getElementsByTags('li');
for(var i=0;i<liUnion.length;i++){
  var spanThird=liUnion[i].getElementsByTags('span')[2];
  //do something
}


------解决方案--------------------
<DIV class="time_lbc">
<UL id=index_tab01>
<LI onMouseOver="this.className='b'" onMouseOut="this.className=''">
  <span class="cx">XX</span>
  <SPAN class="xm">XX</SPAN>
  <SPAN class="jie" style="display:none">X</span>
  <SPAN class="list">XX</SPAN>
  <SPAN class="address">XX</SPAN>
</LI>
<LI onMouseOver="this.className='b'" onMouseOut="this.className=''">
  <span class="cx">XX</span>
  <SPAN class="xm">XX</SPAN>
  <SPAN class="jie" style="display:none">XX</span>
  <SPAN class="list">XX</SPAN>
  <SPAN class="address">XX</SPAN>
</LI>
<LI onMouseOver="this.className='b'" onMouseOut="this.className=''">
  <span class="cx">XX</span>
  <SPA