IE 找不到用 JS 创建的隐藏字段值
我有一个页面,其中有一些隐藏字段。当用户完成选择几个选项后,这些值将通过脚本 (JS/jQuery) 填充。
现在,如果我单击该页面上的链接,转到链接页面,然后单击后退按钮,FF 和 Safari 就能够读出隐藏字段的值。所以读出值的函数似乎是正确的(无论如何它并不复杂)。
但是 IE(还有 Opera,即使我将 History.navigationMode 设置为兼容)显示空值,即使我可以在 IE 生成的源代码中看到正确的值。
我还添加了一个测试函数,向我显示卸载时的值,效果很好。但点击后退按钮 IE 仍然无法“识别”它们。
我不知道这里的问题是什么。有人吗?
谢谢!
I have a page with a few hidden fields in it. Those get filled with values by a script (JS/jQuery) when the user has finished selecting a couple of options.
Now, if I click a link on that page, go to the linked page and then hit the back-button, FF and Safari are able to read out the values of the hidden fields. So the function to read out the values seems to be correct (it's not complicated anyway).
But IE (and also Opera, even though I set history.navigationMode to compatible) shows me empty values, even though I can see the correct values in the generated sourcecode of IE.
I also added a test function, to show me the values onunload, which worked fine. But hitting the back-button IE still doesn't "recognize" them.
I have no idea what the problem here is. Anyone?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,Firefox 甚至在刷新时保留当前值,而 IE 在刷新时将页面重置为初始值。我想这是同样的东西。没有标准描述这里实际发生的情况,因此您不应该依赖不同的浏览器选择如何处理这种情况。
Actually, Firefox even keeps current values when hitting refresh, while IE resets page to initial values on refresh. I guess this is same stuff. No standards describe what should actually happen here, so you should not rely on how the different browsers choose to handle this scenario.
当使用后退按钮重新输入表单时,您依赖于浏览器自动填写正确的表单字段。 AFAIK,只有 FF 和 Safari 默认执行此操作。 IE等浏览器是否可以激活,我不知道。无论如何,你不能在野外依赖它。
您可能需要使用 Cookie 来解决此问题。您必须设置 cookie 值
onchange
或onunload
,并在页面加载时读出 cookie 值。You are relying on the browser filling the in correct form fields automatically when re-entering a form using the back button. AFAIK, only FF and Safari do this by default. Whether it can be activated in IE and other browsers, I don't know. Anyway, you can't rely on it in the wild.
You may have to work around this using Cookies. You would have to set cookie values
onchange
oronunload
, and read out the cookie values when your page loads.