全选

作者: 林小刀2_0 | 来源:发表于2017-12-15 14:23 被阅读0次
      /*
     *为列表绑定全选事件
     *包裹表单需要有id,类名包含form-list
     *input的class均为checkbox
     */
    checkAll: function() {
        $(document).on('click', '.form-list input.checkbox', function(event) {
            var flag = true,
                id = $(this).parents('form').attr('id'),
                checkbox = $('#' + id + ' input.checkbox')
            checkall = checkbox[0],
                that = $(this)[0];
            if (that == checkall) {
                flag = that.checked;
                checkbox.each(function(index, el) {
                    $(this)[0].checked = flag;
                })
            } else {
                checkbox.each(function(index, el) {
                    if ($(this)[0] != checkall) flag = ($(this)[0].checked == false) ? false : flag;
                })
                checkall.checked = flag
            }
        });
    }

相关文章

网友评论

      本文标题:全选

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