การใช้ jQuery check box all

Post a reply

Smilies
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: การใช้ jQuery check box all

การใช้ jQuery check box all

by M009 » 10/07/2013 5:37 pm

chk.jpg
chk.jpg (8.06 KiB) Viewed 463 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>

Top