jquery点击显示或隐藏内容,可以一次展开多个和点击按钮一次全部展开
XML/HTML Code复制内容到剪贴板
- <div id="page">
- <div id="headingSection">
- <a class="button expand" href="#">展开</a>
- </div>
- <div id="faqSection">
- <dl>
- <dt><span class="icon"></span>FAQ1</dt>
- <dd><a href="../../article_jquerywenzi_21.html">jquery点击显示或隐藏内容,可以一次展开多个和点击按钮一次全部展开</a></dd>
- <dt><span class="icon"></span>2</dt>
- <dd>内容2</dd>
- </dl>
- </div>
- </div>
js代码
JavaScript Code复制内容到剪贴板
- $(document).ready(function(){
- var dl = $('<dl>');
- $('#faqSection').append(dl);
- $('dt').live('click',function(){
- var dd = $(this).next();
- // If the title is clicked and the dd is not currently animated,
- // start an animation with the slideToggle() method.
- if(!dd.is(':animated')){
- dd.slideToggle();
- $(this).toggleClass('opened');
- }
- });
- $('a.button').click(function(){
- // To expand/collapse all of the FAQs simultaneously,
- // just trigger the click event on the DTs
- if($(this).hasClass('collapse')){
- $('dt.opened').click();
- }
- else $('dt:not(.opened)').click();
- $(this).toggleClass('expand collapse');
- return false;
- });
- });
原文地址:http://www.freejs.net/article_jquerywenzi_21.html