<input type="checkbox" id="checkAll" value="1">全选/全部不选
<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">
<input type="button" onclick="show()" value="提示选择的">
<script>
$("#chekcAll").click(function(){
if(this.checked){
$("input[name=items]").attr("checked","checked");
}
else{
$("input[name=items]").attr("checked",null);
}
})
function show(){
var strIds=new Array();//声明一个存放id的数组
$("input[name=items]").each(function (i,d){
if (d.checked) {
strIds.push(d.value);
}
})
if(strIds.length<1)
alert("您没有选中项!");
else{
var ids=strIds.join(",");
alert("你选中的字符串有:"+ids);
}
}
</script>