美文网首页
前端 全选移除监听

前端 全选移除监听

作者: wj_39ed | 来源:发表于2020-09-23 14:03 被阅读0次
 <script>
    $(document).ready(function () {

        //监听移除按钮
        $('.btn-remove').click(function () {
            var id = $(this).closest('tr').data('id')
            swal({
                title: "确认移除?",
                icon: 'warning',
                buttons: ['取消','确定'],
                dangerMode: true
            })
            .then(function (willDo) {
                //点取消,willDo 值为false
                if (!willDo){
                    return;
                }
                axios.delete('cartItems/' + id)
                    .then(function () {
                        location.reload()
                    })
            })
        })

        // 监听 全选/取消全选 单选框的变更事件
        $('#select-all').change(function() {
            // 获取单选框的选中状态
            // prop() 方法可以知道标签中是否包含某个属性,当单选框被勾选时,对应的标签就会新增一个 checked 的属性
            var checked = $(this).prop('checked');
            // 获取所有 name=select 并且不带有 disabled 属性的勾选框
            // 对于已经下架的商品我们不希望对应的勾选框会被选中,因此我们需要加上 :not([disabled]) 这个条件
            $('input[name=select][type=checkbox]:not([disabled])').each(function() {
                // 将其勾选状态设为与目标单选框一致
                $(this).prop('checked', checked);
            });
        });
    })

</script>

相关文章

网友评论

      本文标题:前端 全选移除监听

      本文链接:https://www.haomeiwen.com/subject/uufoyktx.html