標籤:io ar for sp on cti ef bs as
--------------全選:
<label><input type="checkbox" id="all"/>全選</label>
<script>
var status=true;
$("#all").click(function(){
if(status){
$("#selectAll input[type=checkbox]").each(function(){
$(this).attr("checked","checked");
});
status=false;
}else{
$("#selectAll input[type=checkbox]").each(function(){
$(this).attr("checked","");
});
status=true;
}
});
</script>
--------------刪除所選:
<input type="button" class="delete" value="刪除所選">
<script>
$(".delete").click(function(){
var chk_len=$("#selectAll input[type=checkbox]:checked").length;//選中個數
var chk_obj=$("#selectAll input[type=checkbox]:checked");//複選框對象
var del_ids=‘‘;
if (chk_len > 0) {
for (var i = 0; i < chk_len; i++) {//組合要刪除的ID
del_ids+=chk_obj.eq(i).val()+‘,‘;
}
del_ids =del_ids.substring(0,del_ids.length-1);//刪除最後一逗號
if (confirm(‘共選擇‘+chk_len+‘條,Are You 確定?‘)) {
location.href = ‘mh/mhDelete?ids=‘+del_ids;
}
} else {
alert(‘至少選擇一項!‘);
}
});
</script>
jquery全選、刪除所選