2013-01-21 151 views
0

當點擊我的開關時,所有我的div展開,因爲代碼是針對所有div的類。我不明白jQuery足以將其改爲只針對相關的div。手風琴開啓所有div開關

的Javascript

$(function() { 
    // The height of the content block when it's not expanded 
    var postadjustheight = 340; 
    // The "more" link text 
    var postmoreText = "Click to Expand Post"; 
    // The "less" link text 
    var postlessText = "Click to Condense Post"; 

    // Sets the .more-block div to the specified height and hides any content that overflows 
    $("body.page-template-page_blog-php #content .post .entry-content").css('height', postadjustheight).css('overflow', 'hidden'); 

    // The section added to the bottom of the "more-less" div 
    $("body.page-template-page_blog-php .entry-content").prepend('<a href="#" class="adjust"></a>'); 

    $("body.page-template-page_blog-php #content .post .adjust").toggle(function() { 
     $("body.page-template-page_blog-php #content .post .entry-content").css('height', 'auto').css('overflow', 'visible'); 
     $(this).text(postlessText); 
    }, function() { 
     $("body.page-template-page_blog-php #content .post .entry-content").css('height', postadjustheight).css('overflow', 'hidden'); 
     $(this).text(postmoreText); 
    }); 
}); 

HTML

<div id="content"> 
    <div class="post"> 
     <div class="entry-content"><a class="adjust" href="#">Click to Expand Post</a> 
      <p>Post Contents</p> 
     </div> 
    </div> 
    </div> 
+2

這是一個JavaScript/jQuery的問題。它與PHP無關。 –

+0

那麼這顯然是我的第一個問題 –

+0

請提供一些HTML結構。 – isherwood

回答