Clicking on label doesn't trigger click event

前端 未结 3 726
清酒与你
清酒与你 2021-01-11 19:10

I have this code:


and

$(\"label\").click(function () {
  $(         


        
3条回答
  •  盖世英雄少女心
    2021-01-11 19:55

    This would be safer to use:

    $(function() {
    
        $('input[type="checkbox"]').bind('change', function (v) {
    
            if($(this).is(':checked')) {
                $(this).parent().addClass('active');
            } else {
                $(this).parent().removeClass('active');
            }
        });
    
    });
    

    Using change instead of click allows for people that navigate forms using the keyboard.

提交回复
热议问题