前端:CheckBox事件函数js


//tbody中多选按钮事件
$("#list-table tbody").on("click", "input[type='checkbox']", function() {
    var allChecked = true;
    $(this).parents("tbody").find("input").each(function() {
        if (!$(this).prop("checked")) {
            allChecked = false;
        }
    });
    $("#checkall").prop("checked", allChecked);
    if (allChecked) {
        $("#checkall").parent("span").prop("class", "checked");
    } else {
        $("#checkall").parent("span").prop("class", "");
    }
});

// thead中全选按钮事件---全选反选
$('#checkall').click( function() {
    if ($(this).prop('checked')) {
        $(this).parents('thead').siblings('tbody').find('input').each(
                function() {
                    $(this).prop('checked', false);
                    $(this).click();
                });
    } else {
        $(this).parents('thead').siblings('tbody').find('input').each(
                function() {
                    $(this).prop('checked', true);
                    $(this).click();
                });
    }
});


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM