//全选
function selectAll() {
if ($('.gwc_all').is(':checked')) {
$(".all").attr("checked", true); //全部选中
} else {
$(".all").attr("checked", false);//全部取消
}
ajax_sum();
}
//获取选中的总价钱
function ajax_sum(){
var ids = '';
$(".all").each(function() {
if ($(this).is(':checked')) {
ids += ',' + $(this).val(); //逐个获取id
}
});
ids = ids.substring(1); // 对id进行处理,去除第一个逗号
$.ajax({
url:"",
data:{ids:ids},
type:'post',
dataType:'json',
success:function(result){
}
})
}
html
<input type="checkbox" onclick="selectAll()" class="gwc_all" id="gwc_all" />全选
<input type="checkbox" class ="all" name='gwc_checked' value='{id}' />