简体   繁体   English

jQuery隐藏和显示基于所选复选框的文本

[英]JQuery Hide and Show Text based on Checkbox Selected

I have a table that is loaded as a partial, I have AJAX callbacks to load the table when either the pagination is selected or display number of items. 我有一个部分加载的表,当选择了分页或显示项目数时,我有AJAX回调来加载该表。 I would like to hide the text until a checkbox is selected. 我想隐藏文本,直到选中一个复选框。 Then show the text which has a count, and a total count of records in the table. 然后在表中显示具有计数和记录总数的文本。 The second part is that I have a link that when pressed allows you to select all items in the table. 第二部分是我有一个链接,当按下该链接时,您可以选择表中的所有项目。

I need some help with this, some of my Jquery: 我需要一些Jquery的帮助:

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

        function check() {
            $(".records-selected").hide();
            $("#selected").text($(".individual:checked").length);
            $("#total").text($(".individual").length);
        }
        check();

Text: 文本:

<li><p class="records-selected"><span id="selected"></span> of <span id="total"></span> records selected</li>
            <li><a href="#" class="number-records">Select All 29 Records</a></li>

Each checkbox has a class of individual and the select all has a class of selectall 每个复选框有一个类的个体和选择都有一类全选

I also need to disable a button called .btn2 if one checkbox is selected. 如果选中了一个复选框,我还需要禁用一个名为.btn2的按钮。 Then if multiple checkboxes are selected then .btn1 is enabled and .btn2 is disabled. 然后,如果选中了多个复选框,则启用.btn1并禁用.btn2。

Any idea on the best way to do this? 有最佳方​​法的想法吗?

// Checks individual checkboxes and displays the count
    $(".individual").on("change", check);

    function check() {
        if ($(".individual:checked").length > 0) {
            $(".records-selected").show();
            $("#selected").text($(".individual:checked").length);
            $("#total").text($(".individual").length);
        }
        else {
            $(".records-selected").hide();
        }
    }
    check();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM