<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>QQ列表展开收缩扩展</title>
<style>
body,ul,p{
padding:0;
margin:0;
}
body{
background-color:#666;
}
li{
list-style:none;
}
#wrap{
width:300px;
height:400px;
margin:30px auto;
}
#wrap p{
font:26px/30px "宋体";
text-indent:1em;
background:#aaa url(../img/ico1.gif) no-repeat 8px center;
}
#list{
border:1px solid #999;
}
#list ul{
display:none;
}
#list .active{
background:#ccc url(../img/ico2.gif) no-repeat 8px center;
}
#wrap li{
border-bottom:1px solid #bbb;
font:16px/26px"宋体";
text-indent:2em;
background-color:#f1f1f1;
}
#wrap li:hover{
background-color:#fff;
}
#wrap .li_style{
background-color:#fff;
}
</style>
<script>
window.onload = function(){
var oList = document.getElementById("list");
var oP = oList.getElementsByTagName("p");
var oUl = oList.getElementsByTagName("ul");
var aLi = null;
var arrLi = [];
for(var i = 0;i < oP.length;i++){
oP[i].index = i;
oP[i].onclick = function(){
if(this.className == ""){
for(var i = 0;i < oP.length;i++){
oP[i].className = "";
oUl[i].style.display = "none";
}
oUl[this.index].style.display = "block";
this.className = "active";
}else{
oUl[this.index].style.display = "none";
this.className = "";
}
}
}
for(var i = 0;i < oUl.length;i++){
aLi = oUl[i].getElementsByTagName("li");
for(var j = 0;j < aLi.length;j++){
arrLi.push(aLi[j]);
}
}
for(var i = 0;i < arrLi.length;i++){
arrLi[i].onclick = function(){
if(this.className ==""){
for(var i = 0;i < arrLi.length;i++){
arrLi[i].className = "";
}
this.className = "li_style";
}else{
this.className = "";
}
}
}
}
</script>
</head>
<body>
<div id = "wrap">
<ul id = "list">
<li>
<p>我的好友</p>
<ul>
<li>张三</li>
<li>张三</li>
<li>张三</li>
<li>张三</li>
</ul>
</li>
<li>
<p>企业好友</p>
<ul>
<li>李四</li>
<li>李四</li>
<li>李四</li>
<li>李四</li>
</ul>
</li>
<li>
<p>黑名单</p>
<ul>
<li>张小三</li>
<li>李小四</li>
</ul>
</li>
</ul>
</div>
</body>
</html>