input type = checkbox problem
Why is this line not working?
<input type="checkbox" checked="no"/>
<input type="checkbox" checked="false"/>
Even though i have specified no and false in checkbox value both are 开发者_如何学Gochecked by default.
Thanks in advance :)
changing it to this will make the first unchecked, and the second checked :
<input type="checkbox" />
<input type="checkbox" checked />
To make the checkbox unchecked you need to remove the word "checked".
Try this -
<input type="checkbox" checked/>
The attribute "Checked" will keep your checkbox checked by default. If you do not have this attribute mentioned, then the checkbox will be unchecked by default.
<input type="checkbox" checked="checked" />
this will pass html validation
Even though i have specified no and false in checkbox value both are checked by default.
this is default behaviour for boolean values in HTML elements.
Only removing the checked
attribute altogether will make the element not checked.
The background is in On SGML and HTML:
Some attributes play the role of boolean variables (e.g., the selected attribute for the OPTION element). Their appearance in the start tag of an element implies that the value of the attribute is "true". Their absence implies a value of "false".
Boolean attributes may legally take a single value: the name of the attribute itself (e.g., selected="selected").
If you are purpose is validation and using jquery then you might need to use "change" event rather than "click".
精彩评论