2013-02-27 58 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