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. JQuery的保留類選擇菜單
- 7. 在Silverlight中保留狀態3
- 8. 保存並加載菜單狀態c#
- 9. Actionbar在Gingerbread中保留菜單項
- 10. Jquery手風琴菜單 - 保留所選菜單打開
- 11. Wordpress菜單選中狀態
- 12. Jquery/HTML下拉菜單懸停狀態
- 13. jQuery的下拉菜單懸停狀態
- 14. 在jquery select2下拉菜單項中保留選項類
- 15. 垂直菜單顯示點擊菜單保持打開狀態
- 16. 保留狀態不工作在android
- 17. jQuery菜單按鈕僅在webkit的下拉菜單中消失,如何讓它保持放置狀態?
- 18. 如何讓父菜單在下拉菜單中的子菜單中保持鼠標懸停狀態
- 19. bootstrap在單擊事件後無法保留狀態
- 20. Chrome擴展簡單彈出不會保留在最後狀態
- 21. 在Android活動中未保留實例狀態的保留碎片
- 22. 菜單狀態 - ASP.Net MVC
- 23. 菜單頁面狀態
- 24. Laravel作業和保留狀態或保留隊列
- 25. 動態生成選擇菜單不在編輯視圖中保持狀態
- 26. 使下拉菜單保持隱形狀態,直到懸停在
- 27. 在不同的菜單列表上保持切換狀態
- 28. 保持家長懸停狀態導航,而在子菜單
- 29. 下拉菜單在觸摸設備上保持打開狀態
- 30. 如何讓菜單在被點擊後保持可見狀態?
我下載的jQuery插件餅乾,現在正在工作。感謝您的幫助。 – 22db05
@Dusko - 很高興能幫到你! – Sam