我有以下jQuery可以展開和摺疊頁面上的部分。 它還會記住哪一部分是最後展開的,並在頁面重新加載時應用。展開/收起所有jquery
我想要做的是在我的頁面上添加一個「全部展開」和「全部摺疊」鏈接,但我不確定該腳本應該是什麼樣子?有任何幫助?
<script type='text/javascript'>
$(function() {
$(".toggle").hide(); //Hide .toggles
$(window).load(function() {
$('.toggle').not(':hidden').prev('.trigger').trigger("click");
});
$('.trigger').each(function() { //For each .trigger
var theActive = $.cookie($(this).attr('id')); //Retrieve the cookies
if (theActive) { //Verify if cookies exist
$('#' + theActive).next(".toggle").slideDown(0); //And slide down the respective .toggle
}
});
$(".trigger").toggle( //Toggle permits alternate clicks
function() {
$(this).next('.toggle').slideDown('slow'); //On odd clicks, .toggle slides down...
$.cookie($(this).attr('id'), $(this).attr('id')); //...and the cookie is set by its ids.
}, function() {
$(this).next('.toggle').slideUp('slow'); //On even clicks, .toggle slides up...
$.cookie($(this).attr('id'), null); //...and the cookie is deleted.
});
});
第1
<div class = "toggle">
Some stuff
</div>
<h3 class = "trigger" id="H1">Section 2</h3>
<div class = "toggle">
More stuff
</div>
$(「。toggle」)。slideDown(); ? – Jeff
試試這個..http://designgala.com/how-to-expand-collapse-toggle-div-layer-using-jquery/ – sharmila
你可以有一些隱藏的變量,並把最後一項點擊和行動的價值。像'#h1;擴大'。然後在準備好的事件中檢查隱藏的值並用';'解析分隔符並根據條件 –