浏览器返回按钮和动态元素 [英] Browser back button and dynamic elements

查看:152
本文介绍了浏览器返回按钮和动态元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面使用jQuery来创建一些 < input> DOM元素,基于什么用户从 < select> 框。

I have a page that uses jQuery to create a number of <input> DOM elements dynamically based on what user picks from a <select> box.

让我们说用户从选择框中选择4 ,我的脚本动态显示4个输入框。

Let's say the user picks 4 from the select box, my script dynamically shows 4 input boxes.

问题是用户刷新或返回此页面(使用浏览器返回按钮)。动态创建的元素不会重新填充到其最后的值,而所有其他静态元素都是。

The problem is when the user refreshes or goes back to this page (with the browser back button). The elements that are created dynamically are not repopulated to their last values, while all the other 'static' elements are.

我在想我可以创建一个隐藏输入,将通过javascript与动态框的内容进行序列化,然后从 $ document.ready 中读取,然后重新填充我的框。

I was thinking I could create a hidden input that would be serialized through javascript with the contents of the dynamic boxes, then read from it on $document.ready and then repopulate my boxes.

有没有更好的方法?

推荐答案

legenden - 有一些可能的解决方案,我会查看这些历史插件一个:

legenden - there are a number of possible solutions to this, I would check out these history plugins for one:

  • History Remote
  • jQuery History plugin
  • Deep Linking plugin

他们有点慌张,但哟你应该能够把一些积极的东西搞清楚。我还将补充说,这可以通过将动态元素存储在cookie中,并以某种方式重新填充来实现。查看 jQuery Cookie插件。希望能帮助你开始。

They are a little fidgety, but you should be able to hack up something positive. I will also add, that this can probably be done by storing the dynamically elements in a cookie(s) and somehow repopulating. Check out the jQuery Cookie plugin. Hope that helped you get started.

这篇关于浏览器返回按钮和动态元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆