批删,全选

<th>全选<input type="checkbox" onclick="all_()" class="che_"></th>
<td><input type="checkbox" name="check_" value="<?php echo $v['w_id'] ?>"></td>
function dels() //批删
{
var w_id = '';
$('input[name=check_]').each(function () {
if ($(this).is(':checked')) {
w_id += ',' + $(this).val();
}
});
if(w_id==''){
alert('还没有选中呢');
}else{
if (confirm('确认删除吗?')) {
$.ajax({
url: 'index.php?r=hshuo/dels',
data: {id: w_id.substr(1)},
// datatype:'json',
type: 'post',
success: function (txt) {
if (txt > 0) {
$('input[name=check_]').each(function(){
if($(this).is(':checked')){
$(this).parent().parent().remove(); //删除节点
}
});
$('.che_').prop('checked',false); //把全选变成不选中的状态

alert('删除成功');
} else {
alert('删除失败')
}
}
})
}
}
}
function all_() //全选
{
if($('.che_').is(':checked')){
$('input[name=check_]').prop('checked',true);
}else {
$('input[name=check_]').prop('checked',false);
}
}
原文地址:https://www.cnblogs.com/taikongliu/p/6358438.html