开发者

Click a li to check / uncheck a checkbox

开发者 https://www.devze.com 2023-04-03 06:23 出处:网络
I applied the next code 开发者_如何学Cto make the li check/uncheck a child checkbox when clicked. The issue is that when clicking the checkbox itself it doesn\'t work. I already read the post here and

I applied the next code 开发者_如何学Cto make the li check/uncheck a child checkbox when clicked. The issue is that when clicking the checkbox itself it doesn't work. I already read the post here and tried to apply the e.stopPropagation(); but still not working, any ideas?

 $('#columnList li').click(function(){
            var check = $(this).children();
            var checkVal = check.attr('value');
            var helper = $('.' + checkVal);
            console.log(helper);
            if(check.is(':checked')){
                check.attr('checked','');
                $.each(helper, function(i, e){
                    $(helper[i]).hide();
                });
            }else{
                check.attr('checked','checked');
                $.each(helper, function(i, e){
                    $(helper[i]).show();
                });
           } 
        });

        $('input[type="checkbox"]').click(function(){
            e.stopPropagation();
        });

HTML is a normal ul with a child checkbox. Nothing special about that.


Try changing -

$('input[type="checkbox"]').click(function(){
            e.stopPropagation();
        });

to -

$('input[type="checkbox"]').click(function(e){
            e.stopPropagation();
        });


You should try to pass event to the function

$('input[type="checkbox"]').click( function(e) {
    e.stopPropagation();
});
0

精彩评论

暂无评论...
验证码 换一张
取 消