0

我使用 icheck 插件设计了我的复选框,并使用了一个和多个复选框(全部选中),如下所示:

HTML:

<div>Using Check all function</div>
<div id="action" class="action-class" style="display:none">SHOW ME</div> 
<div id="selectCheckBox">
    <input type="checkbox" class="all" />Select All
    <input type="checkbox" class="check" />Check Box 1
    <input type="checkbox" class="check" />Check Box 2
    <input type="checkbox" class="check" />Check Box 3
    <input type="checkbox" class="check" />Check Box 4
</div>

JS:

$(function () {
    var checkAll = $('input.all');
    var checkboxes = $('input.check');

    $('input').iCheck();

    checkAll.on('ifChecked ifUnchecked', function(event) {        
        if (event.type == 'ifChecked') {
            checkboxes.iCheck('check');
        } else {
            checkboxes.iCheck('uncheck');
        }
    });

    checkboxes.on('ifChanged', function(event){
        if(checkboxes.filter(':checked').length == checkboxes.length) {
            checkAll.prop('checked', 'checked');
        } else {
            checkAll.removeProp('checked');
        }
        checkAll.iCheck('update');
    });
});

我有<div id="action" class="action-class" style="display:none">SHOW ME</div>display:none

现在,我需要显示div 是否选中了任何复选框(全部和一个)输入。

我怎么能显示这个!?

演示JSFIDDLE

4

2 回答 2

0

可以做这样的事情,根据是否选中任何框来切换 div

function toggleDiv(){
    var showDiv=checkboxes.filter(':checked').length;
    $('#action').toggle(showDiv); /* if boolean argument, toggle will hide/show based on boolean */
}

checkboxes.on('ifChanged', function(event){
    if(checkboxes.filter(':checked').length == checkboxes.length) {
        checkAll.prop('checked', 'checked');
    } else {
        checkAll.removeProp('checked');
    }
    checkAll.iCheck('update');
    toggleDiv();

});

DEMO

于 2014-10-01T17:06:57.583 回答
0
    checkboxes.on('ifChanged', function(event){
        if(checkboxes.filter(':checked').length == checkboxes.length) {
            checkAll.prop('checked', 'checked');
        } else {
             checkAll.removeProp('checked');
        }
        checkAll.iCheck('update');

        //Add this -----------------------------------
        if(checkboxes.filter(':checked').length > 0) {
           $("#action").show();
        }
        else{
           $("#action").hide();
        }
   });

演示:jsfiddle

于 2015-12-05T19:02:05.780 回答