日期:2014-05-16 浏览次数:20352 次
var lis=document.getElementsByTagName("li"); function Change(obj){ for(var i=1;i<lis.length;i++){ if(lis[i].onmouseover==null && lis[i].onmouseout==null){ lis[i]=this; lis[i]. onmouseover=function(){this.style.background='#FAFAFA'}; lis[i].onmouseout=function(){this.style.background=''}; getFirstChild(lis[i]).style.visibility="hidden"; } if(lis[i].id == obj.id){ obj.style.background='blue'; obj.onmouseover=""; obj.onmouseout=""; getFirstChild(obj).style.visibility="visible"; }else{ lis[i].style.background=''; } } } //获取指定节点的第一个子节点 function getFirstChild(obj) { var result = obj.firstChild; while (!result.tagName) { result = result.nextSibling; } return result; }
<div id="play_list"> <div class="divScroll"> <ul style="list-style:none"> <li class="pl-title">播放列表:</li> <?php for($i=0;$i<30;$i++){ ?> <li id="pl-<?php echo $i ?>" onmouseover="this.style.background='#FAFAFA';" onmouseout="this.style.background='';" onclick="Change(this);"> <img class="pl-img" src="../images/music.gif" /> <a href="#">Katy Perry - The One That Got Away</a> </li> <?php } ?> </ul> </div> </div>