<script type="text/javascript">
function selectAll(checked){
var checkBoxs = document.getElementsByName("boxId");
for(var i = 0;i<checkBoxs.length;i++){
checkBoxs[i].checked = checked;
}
}
function deleteChecked(){
var checkBoxs = document.getElementsByName("boxId");
var boxIds = [];
for(var i = 0;i<checkBoxs.length;i++){
if(checkBoxs[i].checked) boxIds.push(checkBoxs[i].value);
}
if(boxIds.length < 1){
alert("请至少选择一条数据...");
return;
}
console.info(boxIds);
}
</script>
<input type="checkbox" οnchange="selectAll(this.checked)"/>全/不选
<br/>
<input type="checkbox" value="1" name="boxId"/>
<input type="checkbox" value="2" name="boxId"/>
<input type="checkbox" value="3" name="boxId"/>
<input type="checkbox" value="4" name="boxId"/>
<input type="checkbox" value="5" name="boxId"/>
<input type="checkbox" value="6" name="boxId"/>
<input type="checkbox" value="7" name="boxId"/>
<input type="button" value="删除" οnclick="deleteChecked()"/>
转载于:https://my.oschina.net/dslcode/blog/1591262