使用 onChange 属性以内联方式更改复选框的值

Change the value of a checkbox inline using the onChange attribute

本文关键字:复选框 方式更 onChange 属性 使用      更新时间:2023-09-26

我做错了还是不可能?我想将复选框的值设置为"0"(如果未选中)和"1"(如果选中)

<input type="checkbox" onChange="function() {$(this).val(this.checked? '1': '0')};" />

注意:我知道如何在onChange事件之外或通过执行onChange="takeCareOfThis()"来执行此操作,我希望以内联方式完成所有操作

你只需要设置要执行的语句。

<input type="checkbox" onChange="$(this).val(this.checked? '1': '0');" />