21,886
社区成员
发帖
与我相关
我的任务
分享
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
<script type="text/javascript">
$(function(){
var items=$("#inputs").children("[type=checkbox]");
/*全选,全不选*/
$("#all").on('click',function(){
if($("#all").is(":checked")){
items.each(function(index, value){
$(this).attr("checked",true);
});
}else{
items.each(function(index, value){
$(this).attr("checked",false);
});
}
});
});
/*获取check数值方法*/
function delAtr(){
/*获取选中元素数值*/
var arr=[];
$("input[name='items']:checked").each(function(index,value){
// 将值加到数组
arr.push(this.value);
});
/*数组序列化*/
var jsonData=JSON.stringify(arr);
$.ajax({
url: 'Formajax.php',
type: 'POST',
dataType: 'text',
data:jsonData,
})
.done(function(sdata) {
console.log(sdata);
})
}
</script>
</head>
<body>
<div id="select2">
<input type="checkbox" id="all">选择
</div>
<div id="inputs">
<input type="checkbox" name="items" value="1" />1#
<input type="checkbox" name="items" value="2" />2#
<input type="checkbox" name="items" value="3" />3#
<input type="checkbox" name="items" value="4" />4#
<input type="checkbox" name="items" value="5" />5#
<input type="checkbox" name="items" value="6" />6#
<input type="checkbox" name="items" value="7" />7#
<input type="checkbox" name="items" value="8" />8#
<input type="checkbox" name="items" value="9" />9#
<input type="checkbox" name="items" value="10" />10#
</div>
<a href="javascript:void(0);" onclick="delAtr();">删除</a>
print_r($_POST);
data:'id='+jsonData