为什么重新加载页面时复选框保持选中状态? [英] Why does the checkbox stay checked when reloading the page?

查看:40
本文介绍了为什么重新加载页面时复选框保持选中状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在重新加载具有以下代码的网页:

I'm reloading a web page that has the following code:

<label for="showimage">Show Image</label>
<input id="showimage" name="showimage" type="checkbox" value="1" />

即使每次重新加载页面时,发送到浏览器的 HTML 都是相同的,但在执行重新加载时,复选框始终采用选中的值.换句话说,如果用户选中复选框并重新加载,复选框仍然被选中.

Even though the HTML stays sent to the browser is the same for each reload of the page, the checkbox always takes on the checked value when a reload was performed. In other words, if the user checks the checkbox and reloads, the checkbox is still checked.

这里有缓存吗?

编辑:我尝试了下面的 Gordon Bell 解决方案,发现即使删除 value="1" 后,这种情况仍然会发生.还有什么我可能遗漏的吗?

Edit: I tried Gordon Bell's solution below and find that this is still happening even after removing the value="1". Anything else I might be missing?

<label for="showimage">Show Image</label> 
<input id="showimage" name="showimage" type="checkbox" /> 

推荐答案

是的,我相信它是缓存.例如,我在 Firefox 上看到了这种行为(不是 Safari,这是值得的:)).

Yes, I believe it is caching. I see this behaviour on Firefox for example (not Safari, for what that's worth :) ).

您可以使用 CTRL-SHIFT-R 重新加载页面并绕过缓存(在 Firefox 上),您将看到检查值不携带(普通的 CTRL-R 会从缓存中获取信息)

you can reload the page and bypass the cache (on Firefox) using CTRL-SHIFT-R and you'll see the check value doesn't carry (a normal CTRL-R will grab the info from the cache however)

编辑:我能够在 Firefox 上禁用此服务器端,设置缓存控制标头:

edit: I was able to disable this server side on Firefox, setting a cache control header:

Cache-Control: no-store

这似乎禁用了 Firefox 的记住表单值"功能

this seems to disable the "remember form values" feature of Firefox

这篇关于为什么重新加载页面时复选框保持选中状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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