首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >折叠打开所有div on切换

问折叠打开所有div on切换
EN

Stack Overflow用户
提问于 2013-01-22 00:04:48
回答 1查看 115关注 0票数 0

当单击我的开关时,我的所有div都会展开,因为代码针对的是所有div的类。我对jQuery的理解还不够深入,不能把它改成只针对相关的div。

Javascript

代码语言: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

代码语言:javascript
复制
    <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>
EN

回答 1

Stack Overflow用户

发布于 2013-01-22 01:27:06

学习jQuery的第一步是不了解jQuery。

包括这个库http://plugins.learningjquery.com/expander/,您应该能够根据切换来扩展/收缩您想要的特定类。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14442548

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档