小编use*_*860的帖子

jQuery 切换 div,展开全部折叠并在页面加载时保持选中第一个项目

我有一些关于我试图添加到我的 jQuery 的功能的问题,以启用按钮或文本以在单击时扩展/收缩所有 div... 我想弄清楚如何在打开时保持第一个 div页面加载。

这是jQuery:

(document).ready(function(){

//Hides containers on load
$(".toggle_container").hide(); 

//Switch "Open" and "Close" state on click
$("h2.trigger").toggle(function(){
    $(this).addClass("active");
    }, function () {
    $(this).removeClass("active");
});

//Slide up and down on click
$("h2.trigger").click(function(){
    $(this).next(".toggle_container").slideToggle("slow");
    });
});
Run Code Online (Sandbox Code Playgroud)

和CSS:

// uses a background image with an on (+) and off (-) state stacked on top of each other
h2.trigger { background: url(buttonBG.gif) no-repeat;height: 46px;line-height: 46px;width: 300px;font-size: 2em;font-weight: normal;}
h2.trigger a {color: #fff;text-decoration: none; display: block;}
h2.active {background-position: left bottom;}
.toggle_container …
Run Code Online (Sandbox Code Playgroud)

css jquery toggle

4
推荐指数
1
解决办法
7948
查看次数

标签 统计

css ×1

jquery ×1

toggle ×1