前端: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