Page 1 of 1

การใช้ jQuery check box all

Posted: 10/07/2013 5:37 pm
by M009
chk.jpg
chk.jpg (8.06 KiB) Viewed 461 times
เวอร์ชั่นปัจจุบัน จะใช้

Code: Select all

  jQuery(this).prop('checked', true);
แทนการใช้

Code: Select all

jQuery(this).attr('checked', true);

Code: Select all

<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    <script>
            jQuery(document).on("click","#check_all",function() {
                    jQuery('.chk').each(function(i) {
                            jQuery(this).prop('checked', true);
                    });
                return false ;
            });
            jQuery(document).on("click","#uncheck_all",function() {
                    jQuery('.chk').each(function(i) {
                            jQuery(this).prop('checked', false);
                    });
                return false; 
            });
    </script>
</head>
<body>
    <input id="1" class="chk" type="checkbox" name="chkDel[]" value="1" >
    <input id="2" class="chk" type="checkbox" name="chkDel[]" value="2" >
    <input id="3" class="chk" type="checkbox" name="chkDel[]" value="3" >
    <div> <button id="check_all">checkall</button> <button id="uncheck_all">uncheckall</button></div>
</body>