Why does the checkbox stay checked when reloading

2019-01-04 09: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" />

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" /> 

标签: firefox
8条回答
Summer. ? 凉城
2楼-- · 2019-01-04 09:53

Add autocomplete="off" into the form element on the page. The downside is that this isn't valid XHTML, but it fixes the issue without any convoluted javascript.

查看更多
我想做一个坏孩纸
3楼-- · 2019-01-04 09:58

set autocomplete="off" with js is also working well.

for example using jquery:

$(":checkbox").attr("autocomplete", "off");
查看更多
beautiful°
4楼-- · 2019-01-04 09:58

$("#showimage").prop("checked",false);

查看更多
ゆ 、 Hurt°
5楼-- · 2019-01-04 10:01

or instead of f5 press enter on address bar :)

查看更多
beautiful°
6楼-- · 2019-01-04 10:07

the public idea to solve that

make form & reset button

<form>
<checkbox>
<reset>
</form>

$(reset).trigger("click");//to clear the cache and input 
$(checkbox).trigger("click");//to mark checkbox
查看更多
三岁会撩人
7楼-- · 2019-01-04 10:09

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

查看更多
登录 后发表回答