为什么重新加载页面时复选框会保持被选中状态? [英] Why does the checkbox stay checked when reloading the page?
问题描述
< label for =showimage>显示图片< / label>
< input id =showimagename =showimagetype =checkboxvalue =1/>
即使HTML保持发送到浏览器对于每次重新加载页面都是一样的,复选框在执行重新加载时总是取得选中的值。换句话说,如果用户选择复选框并重新加载,复选框仍然被选中。
这里有一些缓存吗?
编辑:我尝试了下面的Gordon Bell的解决方案,发现即使在删除值=1之后,仍然发生这种情况。
< label for =showimage>显示图像< / label>
< input id =showimagename =showimagetype =checkbox/>
是的,我相信这是缓存。我在Firefox上看到这种行为(不是Safari,值得:))。
您可以重新加载页面并绕过缓存(在Firefox上)使用< kbd> CTRL - SHIFT - R ,你会看到检查值没有进行(正常 CTRL 然而,kbd> R 会抓取缓存中的信息)
编辑:我可以在Firefox上禁用此服务器端,设置一个缓存控制头:
Cache-Control:no-store
这似乎禁用Firefox的记住表单值功能
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" />
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.
Is there some caching going on here?
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" />
Yes, I believe it is caching. I see this behaviour on Firefox for example (not Safari, for what that's worth :) ).
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)
edit: I was able to disable this server side on Firefox, setting a cache control header:
Cache-Control: no-store
this seems to disable the "remember form values" feature of Firefox
这篇关于为什么重新加载页面时复选框会保持被选中状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!