手风琴在开关时打开所有div

时间:2013-01-21 16:04:48

标签: javascript jquery wordpress

单击我的切换时,我的所有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>

1 个答案:

答案 0 :(得分:0)

不知道jQuery是学习jQuery的第一步。

加入此库http://plugins.learningjquery.com/expander/ 并且您应该能够根据切换扩展/收缩您想要的特定类。