php查询列表可展开和收缩,JavaScript实现QQ列表展开收缩扩展功能的示例

本文实例为大家分享了js实现QQ列表展开收缩扩展展示的具体代码,供大家参考,具体内容如下

效果图:

83ee47f295ba3d77fbd157db365279d4.gif

代码:

无标题文档

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';

}

}

};

我的好友

张三张四张五张六

企业好友

  • 李四
  • 李小四
  • 李四二
  • 李毅
  • 李二

黑名单

  • 张三
  • 李四
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以使用jQuery的`slideToggle()`方法来实现同一页面多个DIV层的展开收缩功能。具体步骤如下: 1. 给需要展开收缩的DIV层添加一个class类,比如"expandable"。 2. 在jQuery中使用`$(".expandable")`来选择所有的需要展开收缩的DIV层。 3. 使用`click()`方法来监听DIV层的点击事件。 4. 在点击事件中使用`slideToggle()`方法来展开收缩DIV层。 示例代码如下: ```html <!DOCTYPE html> <html> <head> <title>HTML多层展开,jQuery实现同一页面多个DIV层展开收缩功能</title> <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <style type="text/css"> .expandable { background-color: #f0f0f0; padding: 10px; margin-bottom: 10px; cursor: pointer; } .expandable-content { display: none; } </style> </head> <body> <div class="expandable"> <h3>第一层</h3> <div class="expandable-content"> <p>第一层内容</p> </div> </div> <div class="expandable"> <h3>第二层</h3> <div class="expandable-content"> <p>第二层内容</p> </div> </div> <div class="expandable"> <h3>第三层</h3> <div class="expandable-content"> <p>第三层内容</p> </div> </div> <script type="text/javascript"> $(document).ready(function() { $(".expandable").click(function() { $(this).find(".expandable-content").slideToggle(); }); }); </script> </body> </html> ``` 在上述代码中,我们使用了一个`.expandable`的class来选择需要展开收缩的DIV层,并且在点击事件中使用了`slideToggle()`方法来展开收缩DIV层。同时,我们也添加了一些CSS样式来美化界面。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值