1
A
回答
2
如何使用Cookie來跟蹤狀態?
0
我通常在URL和散列輪詢中使用#hash標籤來實現這一點。
下面是一個例子:
<a href="#showdiv">Click here to show div!</a>
var start_hash = window.location.hash;
var recent_hash = "";
process_hash(start_hash); // Start the initial hash check
setInterval(poll_hash, 100); // Initialize our hash polling interval
function poll_hash() {
if (window.location.hash==recent_hash) { return; } // No change in URL hash
recent_hash = window.location.hash; // Set to check next time.
process_hash(recent_hash); // Changed hash, lets process
}
// process_hash
function process_hash(current_hash) {
// Check for defaults, then set to #home.
if(!current_hash || current_hash == '') { current_hash="#home"; }
// Strip the # for the hash
var hash_id = link_div.match(/[^#]+/g);
// conditions for multiple hash tags can go here.
if(hash_id == "#showdiv") {
$("#somediv").show();
}
}
+0
這當然是通過url.com/page.php#showdiv來恢復狀態。如果您有多個元素,或者取決於您是否希望狀態在客戶端之間保存,則可能需要使用Cookie來跟蹤狀態。 –
相關問題
- 1. 在視圖中保留菜單樹狀態 - ASP.NET MVC 3
- 2. 在最後點擊的菜單項上保留懸停狀態
- 3. jquery菜單記住菜單的狀態
- 4. 下拉菜單保持選中狀態
- 5. 保留固定左側菜單的點擊狀態
- 6. 子菜單項目不保留當前狀態
- 7. JQuery數據表+表狀態不保留
- 8. jQuery懸停狀態在導航菜單上保持閃爍
- 9. JQuery的保留類選擇菜單
- 10. 當前狀態保留在listview android中。
- 11. 不想在android中保留Webview狀態
- 12. 在Silverlight中保留狀態3
- 13. Jquery手風琴保持菜單狀態菜單中不包含在菜單內的鏈接
- 14. 保存並加載菜單狀態c#
- 15. Ember - 保存子菜單狀態
- 16. Actionbar在Gingerbread中保留菜單項
- 17. Jquery手風琴菜單 - 保留所選菜單打開
- 18. 保留複選框狀態
- 19. 保留Android活動狀態
- 20. 保留Kendo Grid狀態
- 21. 保留頁面狀態
- 22. Wordpress菜單選中狀態
- 23. 用jquery手風琴風格菜單(Maccordion)保存狀態
- 24. Jquery/HTML下拉菜單懸停狀態
- 25. jQuery的下拉菜單懸停狀態
- 26. 垂直菜單顯示點擊菜單保持打開狀態
- 27. 在jquery select2下拉菜單項中保留選項類
- 28. 保留Bootstrap側面菜單
- 29. 在fnDraw()上保留分頁狀態
- 30. 保留狀態不工作在android
我下載的jQuery插件餅乾,現在正在工作。感謝您的幫助。 – 22db05
@Dusko - 很高興能幫到你! – Sam