Watch for change of the input[type=“checkbox”]

前端 未结 5 1956
旧时难觅i
旧时难觅i 2021-02-13 15:17

How can I run a function on checkbox change?

I\'m trying to write small checkbox replacing function base on that - but I\'m doing something wrong.

Code:

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-13 15:56

    Try this:

    $('input[type=checkbox]').change(function() {
        alert("I'm changed!");
    });
    

    Or

    $('input[type=checkbox]').change(function() {
        if ($(this).is(':checked')) {
            alert('I\'\m --> checked');
        } else {
            alert('I\'\m --> unchecked');
        }
    });
    

提交回复
热议问题