2013-01-21 111 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

回答