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