Jquery 在实时单击和窗口 setTimeout 上保存切换状态
我想知道。当我使用ajax获取数据并使用时如何保存事件状态(toggle()) 窗口 setTimeout 以保持数据最新。
我有这段代码每 10 秒刷新一次窗口
window.setTimeout("load_data()", 10000);
,并且在加载数据和发生切换()事件的 div 上,
$('#maindiv #click').live('click', function(event) {
$('#togglediv').toggle();
});
一切正常,除了当每 10 秒加载窗口时,切换状态会重置。 我该如何解决这个问题或者可能是一个解决方案。
提前致谢!
I was wondering. How to save an event state ( toggle() ) while I am getting data with ajax and using
window setTimeout to keep the data fresh.
I have this code to refresh window every 10 seconds
window.setTimeout("load_data()", 10000);
And on the div where data is loaded and toggle() event takes place
$('#maindiv #click').live('click', function(event) {
$('#togglediv').toggle();
});
Every thing works fine, except that when window is loaded every 10 seconds then the toggle state is reset.
How can I fix that or maybe a workaround solution.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只想使用客户端技术,则可以使用 cookie。看看http://www.electrictoolbox.com/jquery-cookies/。
您还可以使用 url 参数,但我想 cookies 会是更好的方法。
If you want to work only with client side technology, you can use cookies for that. Take a look at http://www.electrictoolbox.com/jquery-cookies/.
You can also work with url parameters, but I guess cookies would be a better approach.
当刷新页面时,您可以将toggled = 0或toggled = 1作为参数传递给您的URL,
并通过后端脚本(PHP 或 ASP.NET)打印它们,将它们存储为 javascript 变量。
You can pass toggled = 0 or toggled = 1 as parameters to your URL when you refresh the page,
and have them stored as javascript variable, by printing them through your backend script ( PHP or ASP.NET).