简体   繁体   中英

Change the value of a checkbox inline using the onChange attribute

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');" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM