jQuery 實現復選框的全選與反選


    <script>
        //實現全選與反選
        $(".allAndNotAll").click(function () {
            if ($(this).prop("checked")) {
                $("input[id=inlineCheckbox1]:checkbox").each(function () {
                    $(this).prop("checked", true);
                });
            } else {
                $("input[id=inlineCheckbox1]:checkbox").each(function () {
                    $(this).prop("checked", false);
                });
            }
        });
        //當其中不勾選某一個選項的時候,則去掉全選復選框
        $(":checkbox[id=inlineCheckbox1]").click(function () {
            $(".allAndNotAll").prop('checked',
                $(":checkbox[id=inlineCheckbox1]").length == $(":checkbox[id=inlineCheckbox1]:checked").length);
        });
    </script>
<!-- 全選按鈕 -->  
<label for="exampleInputEmail2">全選</label>
 <input type="checkbox" class="allAndNotAll">
 <!-- 單選框 -->                
<td><input type="checkbox" value="{{ data.id }}" name="product_bound_id" id="inlineCheckbox1"></td>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM