欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery實現(xiàn)全選&全不選&非全選

 更新時間:2017年03月23日 15:08:42   作者:wizx1992  
本文主要介紹了jQuery實現(xiàn)全選&全不選&非全選,具有很好的參考價值,下面跟著小編一起來看下吧

 1.點擊全選 選中/取消所有復(fù)選框

2.取消某一個復(fù)選框,全選按鈕不選中

3.勾選所有復(fù)選框后,全選按鈕選中

<div>
        <div><input type="checkbox" name="checkbox" />復(fù)選框1</div>
        <div><input type="checkbox" name="checkbox" />復(fù)選框2</div>
        <div><input type="checkbox" name="checkbox" />復(fù)選框3</div>
        <div><input type="checkbox" name="checkbox" />復(fù)選框4</div>
        <div><input type="checkbox" name="checkbox" />復(fù)選框5</div>
        <br>
        <div><input type="checkbox" name="checkall" />全選</div>
    </div>
        $('input[name="checkall"]').click(function(){
            if($(this).is(':checked')){
                $('input[name="checkbox"]').each(function(){
                    $(this).prop("checked",true);
                });
            }else{
                $('input[name="checkbox"]').each(function(){
                    $(this).prop("checked",false);
                });
            } 
        });
        // 全選
        $('input[name="checkall"]').click(function(){
            if($(this).is(':checked')){
                $('input:checkbox[name=checkbox]').each(function(){
                    $(this).prop("checked",true);
                })
            }else{
                $('input:checkbox[name=checkbox]').each(function(){
                    $(this).prop("checked",false);
                })
            }
        })
        var ifAllChecked = true;
        // 是否全選-----是否選中全選按鈕
        $('input:checkbox[name=checkbox]').click(function(){
            ifAllChecked = true
            $('input:checkbox[name=checkbox]').each(function(i){
                if(!$(this).is(':checked')){
                    // 有未選
                    ifAllChecked = false; 
                }
            });
            if(ifAllChecked){
                $('input[name="checkall"]').prop("checked",true);
            }else{
                $('input[name="checkall"]').prop("checked",false);
            }
        })

相關(guān)文章

最新評論