Javascript checkbox onChange

后端 未结 10 1194
孤街浪徒
孤街浪徒 2020-11-28 06:00

I have a checkbox in a form and I\'d like it to work according to following scenario:

  • if someone checks it, the value of a textfield (totalCost)
10条回答
  •  北海茫月
    2020-11-28 06:28

    The following solution makes use of jquery. Let's assume you have a checkbox with id of checkboxId.

    const checkbox = $("#checkboxId");
    
    checkbox.change(function(event) {
        var checkbox = event.target;
        if (checkbox.checked) {
            //Checkbox has been checked
        } else {
            //Checkbox has been unchecked
        }
    });
    

提交回复
热议问题