单击li以选中/取消选中复选框 [英] Click a li to check / uncheck a checkbox

查看:172
本文介绍了单击li以选中/取消选中复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应用了下一个代码,以便在单击时检查/取消选中子复选框。问题是,当单击复选框本身不工作。我已阅读此处的帖子,并尝试将 e.stopPropagation(); 但仍然不工作,任何想法?

I applied the next code to 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是正常的 ul 复选框。没有什么特别的。

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

推荐答案

尝试更改 -

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

至 -

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

这篇关于单击li以选中/取消选中复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆