โค้ด: เลือกทั้งหมด
jQuery(this).prop('checked', true);
โค้ด: เลือกทั้งหมด
jQuery(this).attr('checked', true);
โค้ด: เลือกทั้งหมด
<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>