How to explicitly set checkbox unchecked
I have a xhtml page with transitional doctype having a checkbox that I want to be unchecked after loading. No JavaScript! In Firefox 3.5 (for instance, there may be other browsers) user can check input,开发者_运维问答 than reload page and get input checked. How can I overcome this behaviour?
Use
autocomplete="off"
Also have a look at Why does the checkbox stay checked when reloading the page?
You can't do much to change a document's state with HTML alone. All you can do is set checked="checked"
or not.
You need either JavaScript or a server side language to determine whether that attribute should be set or not.
You can't, not without JavaScript. This is Firefox specific behaviour which would occur even if you could explicitly force an "unchecked" state (which you can't, because the absence of checked
already means that.)
The only non-Javascript way that I know of is to rename the form element on server-side on every request so FF has no chance of storing the value.
To explicitly set the checkbox to unchecked, the following worked for me:
<input type="checkbox" unchecked>
Try to put in your code this:
<p><label><input id="test" type="checkbox"></input>Test checkbox</label></p>
It will be unchecked when the page starts or refreshes.
精彩评论