2013-02-27 55 views
0

我使用Simple-Expandhttp://redhotsly.github.com/simple-expand/展开和折叠HTML页面中的区域。调用方法展开和折叠区域

jQuery代码:

$(function() { 
    $('.hello').simpleexpand(); 

}); 

$(function() { 
    $('.bye').simpleexpand(); 

}); 

HTML:

<a href='' id='hello' class='hello'> Hi </a> 

      <a href='' id='bye' class='bye'> Bye </a> 

事业部:

<div class="content"> 
    Hello 
</div> 

<div class="content"> 
    Bye 
</div> 

当我点击链接与类hello,只有DIV标签与文本应该调用Hello,当我点击链接应该显示ByeDIV标签和Bye文本。我怎样才能做到这一点 ?

回答

0

试试这个:

jQuery代码:

$(function() { 
    $('a').click(function(){ 
     var id = $(this).attr('id'); 
     var divId = 'div_' + id; 
     $('#'+divId).simpleexpand(); 
    }); 
}); 

HTML:

<a href='' id='hello'class='hello'> Hi </a> 
<a href='' id='bye' class='bye'> Bye </a> 

事业部:

<div class="content" id='div_hello'> 
    Hello 
</div> 

<div class="content" id='div_bye'> 
    Bye 
</div> 
+0

jQuery的功能被炒鱿鱼,但它不不会扩大。 – 2013-02-27 09:30:17

+0

@sharonHwk:请分享http://jsfiddle.net/链接,我们看到您的完整代码。 – 2013-02-28 04:08:05

+0

这是我相信的更好的解决方案,但让我说明Aditya试图做的更好一点。 – 2015-08-14 17:07:42

2

这是所有在您发布的文档:http://sylvain-hamel.github.io/simple-expand/

你必须指定你的看涨期权的simpleexpand方法

例如:

$(function() { 
    $('.hello').simpleexpand({'defaultTarget': '.helloDiv'}); 

}); 

$(function() { 
    $('.bye').simpleexpand({'defaultTarget': '.byeDiv'}); 

}); 

和你的HTML:

<div class="helloDiv"> 
    Hello 
</div> 

<div class="byeDiv"> 
    Bye 
</div> 
+2

我认为JQuery函数中应该有'{}',但它不会展开或折叠。 – 2013-02-27 09:31:03

+0

true ...更正了你评论后的一段时间。 – benzonico 2013-07-25 17:50:19