0
我有一个按钮,切换我的页脚。当前代码从页脚关闭开始。我的问题是我如何使默认状态打开?我已经尝试过几种配置,但不知道什么是正确的。当我在浏览器上检查cookie时,默认状态为'隐藏'。Jquery切换按钮,并关闭状态
// Toggle Button
$(document).ready(function() {
var button = $('.toggle');
//check the cookie when the page loads
if ($.cookie('currentToggle') ==='visible') {
togglePanel(button, false);
}
else {
togglePanel(button, true);
}
//handle the clicking of the show/hide toggle button
button.click(function() {
//toggle the panel as required, base on current state
if (button.text() === "-") {
togglePanel($(this), true);
}
else {
togglePanel($(this), false);
}
});
});
function togglePanel(button, show) {
var panel = $('footer');
if (show) {
panel.slideUp('slow');
button.text('+');
$.cookie('currentToggle', 'hidden', { path: '/' });
}
else {
panel.slideDown('slow');
button.text('-');
$.cookie('currentToggle', 'visible', { path: '/' });
}
}
Cookie的默认状态是它根本不存在。你需要检查这个,然后实现你想要的默认值。 – Barmar