Why isn't my checkbox change event triggered?

后端 未结 3 1822
栀梦
栀梦 2020-12-03 07:20

I have two functions.

The first function translates a div click into a checked/unchecked toggle. The second function translates a checkbox change into a hide/show ev

3条回答
  •  醉酒成梦
    2020-12-03 08:09

    you are using '.' which is for class selectors instead use '#' since you are using the element ID. Like this:

    $(document).ready(function() {
        $(":checkbox").bind('change', function() {
            if($(this).attr("checked")) {
                $('#'+this.id).show();
            }
            else {
                $('#'+this.id).hide();
            }
        });
    });
    

提交回复
热议问题