JQuery展开关闭内容块效果

1 篇文章 0 订阅
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>Jquery展开关闭内容块效果</title>
 <script type="text/javascript" src="jquery-1.5.2.min.js"></script>
 <script type="text/javascript">
 $(function(){
 $(".content").hide(); //隐藏所有主体内容
 $('.s').toggle(function(){
 //选择class为s的元素,并添加toggle方法
 //toggle方法可以切换元素的可见状态,如可见便切换隐藏,反之亦然
 $(this).text('隐藏').parent().nextAll('.content').slideDown();
 //给当前元素添加文本"隐藏",并找到父级元素之后的所有同辈元素.并添加向下展开效果
 },function(){
 $(this).text('展开').parent().nextAll('.content').slideUp();
 //给当前元素添加文本"展开",并找到父级元素之后的所有同辈元素.并添加向上收缩效果
 });
 });
 </script>
  
 <style>
 .demo .title{ font-size:12px; font-weight:bold; text-indent:10px; line-height:25px; margin-top:2px; background:#ccc; border:2px solid #eee;}
 .demo .title span{ float:right; font-size:12px; margin-right:10px; color:#F00; cursor:pointer;}
 .demo .content{ font-size:30px; font-weight:bold; text-indent:10px; border:2px solid #eee; border-top:none; padding:10px;}
 </style>
  
 </head>
 <body>
 <div class="demo">
 <div class="title">大家好,我是标题一<span class="s">展开</span></div>
 <div class="content">大家好,我是内容一</div>
 </div>
 <div class="demo">
 <div class="title">大家好,我是标题二<span class="s">展开</span></div>
 <div class="content">大家好,我是内容二</div>
 </div>
 </body>
 </html>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值