考慮使用HTML5本地存儲 - 目前尚未支持所有瀏覽器,但實現起來非常簡單。
例如:
var foo = localStorage.getItem("foo");
// ...
localStorage.setItem("content", item);
在你的情況下,只需添加一行,以更新的localStorage上市每當它展開或摺疊說「部分」:
// Inside your function:
var state = // whether the 'section' is expanded or collapsed
localStorage.setItem(state, $(this).id());
而當頁面加載
$(section).each(function() { // 'section' should target all collapsible elements
var expanded = localStorage.getItem($(this).id()); // be careful here - make sure it's parsed in the correct format
if (expanded == 1) {
$(this).expand(); // your expand function
} else {
$(this).collapse(); // your collapse function
}
});
Read up about it here
謝謝。這很好用! – reggie 2013-05-12 16:27:49