Jquery实现全选和取消全选的方法,获取选中id的值

 1、全选与取消全选

<input type="checkbox" id="all" />全选<br />  
<input type="checkbox" name="sub" />添加权限<br />  
<input type="checkbox" name="sub" />修改权限<br />  
<input type="checkbox" name="sub" />权限列表<br />  
<script>
    $("#all").on('click',function() {
        $("input[name='sub']").prop("checked", this.checked);
    });

    $("input[name='sub']").on('click',function() {
        var $subs = $("input[name='sub']");
        $("#all").prop("checked" , $subs.length == $subs.filter(":checked").length ? true :false);
    });
</script>

2、获取选中的id的值

// 获取选中的商品id
    function getIds() {
        var ids = "";
        var checkClass = $("input[name='sub']:checked");
        checkClass.each(function() {
            ids+=$(this).val();
            ids+=",";
        });
        ids = ids.substr(0, ids.lastIndexOf(","));
        return ids;
    }
发布了18 篇原创文章 · 获赞 18 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/andwey/article/details/104988516
今日推荐