admin管理员组文章数量:1352788
Am I doing this wrong or is this impossible? I want to set the value of the checkbox to "0" if unchecked, and "1" if checked
<input type="checkbox" onChange="function() {$(this).val(this.checked? '1': '0')};" />
NOTE: I know how to do it outside of the onChange
event or by doing onChange="takeCareOfThis()"
, I'm looking to do it all inline
Am I doing this wrong or is this impossible? I want to set the value of the checkbox to "0" if unchecked, and "1" if checked
<input type="checkbox" onChange="function() {$(this).val(this.checked? '1': '0')};" />
NOTE: I know how to do it outside of the onChange
event or by doing onChange="takeCareOfThis()"
, I'm looking to do it all inline
-
<input type="checkbox" onChange="$(this).val(this.checked? '1': '0');" />
– Satpal Commented Apr 25, 2016 at 8:21 - Don't put the logic in a function block. However, the point of setting the value if the element is checked or not seems pletely redundant. – Rory McCrossan Commented Apr 25, 2016 at 8:21
- I hear you @RoryMcCrossan, it would take too long to explain why, but I do need it here – NaturalBornCamper Commented Apr 25, 2016 at 8:36
1 Answer
Reset to default 7You just need to set the statement to be executed.
<input type="checkbox" onChange="$(this).val(this.checked? '1': '0');" />
本文标签: javascriptChange the value of a checkbox inline using the onChange attributeStack Overflow
版权声明:本文标题:javascript - Change the value of a checkbox inline using the onChange attribute - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743898619a2558255.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论