php 展开收缩,怎样用JS做出列表展开收缩扩展功能
这次给大家带来的是怎样用JS做出列表展开收缩扩展功能,列表展开收缩功能是一个非常实用的功能,这篇文章就给大家好好分析一下。
无标题文档
ul,h2{margin:0; padding:0;}
li{list-style-type:none;}
#list{margin:0 auto; border:#333 solid 1px; width:250px;}
#list h2 {background: url(../img/ico1.gif) no-repeat 5px 14px #0C6; text-indent:20px; height:32px; line-height:32px;}
#list ul li{text-indent:25px; border-bottom:#333 solid 1px; line-height:24px; height:23px; }
#list .active{background: url(../img/ico2.gif) no-repeat 5px 14px #693; text-indent:20px; height:30px; line-height:30px;}
#list ul{display:none;}
.hover{background:#CFC;}
window.onload = function(){
var oUl = document.getElementById(“list”);
var aUl =oUl.getElementsByTagName(“ul”);
var aH2 = oUl.getElementsByTagName(“h2”);
var aLi = null;
var arrLi = [];
var that = null;
for(i=0;i
aH2[i].index = i;
aH2[i].onclick = function(){
if(this.className==’’){
for(i=0;i
aH2[i].className=’’;
aUl[i].style.display=’none’;
}
this.className=’active’;
aUl[this.index].style.display = ‘block’;
}else{
this.className=’’;
aUl[this.index].style.display=’none’;
}
}
}
for(i=0;i
aLi =aUl[i].getElementsByTagName(“li”);
for(j=0;j
arrLi.push(aLi[j]);
}
}
for(var i=0;i
arrLi[i].onclick = function(){
for(i=0; i
arrLi[i].className=’’;
}
this.className = ‘hover’;
}
}
};
我的好友
张三张四张五张六
企业好友
- 李四
- 李小四
- 李四二
- 李毅
- 李二
黑名单
- 张三
- 李四
相信看了以上介绍你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
相关阅读:
还没有评论,来说两句吧...