我有一些关于我试图添加到我的 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)