javascript - onchange event on checkbox always shows this.value = on -
an input of type checkbox when fires onchange
event this.value
set on
when checkbox ticked off in case i'd expect off
is intended behavior?
<input type="checkbox" onchange="alert(this.value)">
short answer: not use value
check checked status on checkboxes, use checked
instead
<input type="checkbox" onchange="alert(this.checked)">
and in case wonder why always-"on" value, there's specification in html5 specification:
default/on
on getting, if element has value attribute, must return attribute's value; otherwise, it must return the string "on". on setting, must set element's value attribute new value.
http://www.w3.org/tr/html5/forms.html#dom-input-value-default-on
Comments
Post a Comment