亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

根據選中的復選框啟用和禁用兩個不同的按鈕 - JQuery

根據選中的復選框啟用和禁用兩個不同的按鈕 - JQuery

C#
慕的地6264312 2021-06-04 11:53:02
我有一個表格,但我需要添加一些功能,以便如果您只選擇一個選項,則單個操作菜單應該處于活動狀態,而頂部操作菜單應該是灰色的。目前,如果您選擇一個選項,它將禁用表格操作菜單并啟用頂部操作菜單。有沒有辦法讓它工作,這樣如果只選擇一個記錄,頂部菜單就會被禁用。目前它是如何工作的:全選 - 禁用表格按鈕,啟用頂部按鈕。如果您取消選擇全選,則該按鈕將被禁用如果您從表格中選擇 2 個或更多,則表格按鈕將被禁用,而頂部菜單將被啟用。查詢// Checks individual checkboxes and displays the count    $(".individual").on("change", determineActionButtonAvailability);    $(".selectall").click(function () {        $(".individual").prop("checked", $(this).prop("checked"));        determineActionButtonAvailability();    });    //Disable Top Verify Button if two or more checkboxes are selected.    $('.verify-btn').prop('disabled', true);    $(".individual").on("click", function () {        if ($(".individual:checked").length > 1) {            $('.verify-btn').prop('disabled', false);        }        else {            $('.verify-btn').prop('disabled', true);        }    });    //Disable Action Button in the columns when more than one checkbox is selected    $('.table-btn').prop('disabled', false);    $(".individual").on("click", function () {        if ($(".individual:checked").length > 1) {            $('.table-btn').prop('disabled', false);            $(".verify-btn").prop('disabled', true);        }        else {            $('.table-btn').prop('disabled', false);            $(".verify-btn").prop('disabled', false);        }    });    // When one or more works are selected, will enable the top action menu.    // Will disable when none selected.    function determineActionButtonAvailability()    {        if ($(".individual:checked").length > 0)        {            $(".records-selected").show();            $("#selected").text($(".individual:checked").length);            $("#total").text($(".individual").length);            $(".verify-btn").prop('disabled', false);            $('.table-btn').prop('disabled', true);        }        else {            $(".records-selected").hide();            $(".verify-btn").prop('disabled', true);            $('.table-btn').prop('disabled', false);        }    }
查看完整描述

1 回答

?
POPMUISE

TA貢獻1765條經驗 獲得超5個贊

所以我設法讓它工作,經過多次撓頭,我將計數更改為 1,這解決了問題。全面測試它現在按預期執行。


    // Checks individual checkboxes and displays the count

    $(".individual").on("change", determineActionButtonAvailability);


    $(".selectall").click(function () {

        $(".individual").prop("checked", $(this).prop("checked"));

        determineActionButtonAvailability();

    });


    //Disable Top Verify Button if two or more checkboxes are selected.

    $('.verify-btn').prop('disabled', true);

    $(".individual").on("click", function () {

        if ($(".individual:checked").length > 1) {

            $('.verify-btn').prop('disabled', false);

        }

        else {

            $('.verify-btn').prop('disabled', true);

        }

    });


    //Disable Action Button in the columns when more than one checkbox is selected

    $('.table-btn').prop('disabled', false);

    $(".individual").on("click", function () {

        if ($(".individual:checked").length > 1) {

            $('.table-btn').prop('disabled', true);

        }

        else {

            $('.table-btn').prop('disabled', false);

        }

    });


    // When one or more works are selected, will enable the top action menu.

    // Will disable when none selected.

    function determineActionButtonAvailability() {

        if ($(".individual:checked").length > 1) {

            $(".records-selected").show();

            $("#selected").text($(".individual:checked").length);

            $("#total").text($(".individual").length);


            $(".verify-btn").prop('disabled', false);

            $(".table-btn").prop('disabled', true);

        }

        else {

            $(".records-selected").hide();


            $(".verify-btn").prop('disabled', true);

            $(".table-btn").prop('disabled', false);

        }

    }



查看完整回答
反對 回復 2021-06-05
  • 1 回答
  • 0 關注
  • 252 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號