单击我的切换按钮时,我的所有 div 都会展开,因为代码针对所有 div 的类。我不太了解 jQuery,无法将其更改为仅针对相关 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>