<html>
<head>
<script type="text/javascript">
function selectAllID(){
var allSel = document.getElementsByName("id");
var selectAll = document.getElementById("selectAll");
var ch = selectAll.checked;
for(var i=0;i<allSel.length;i++){
allSel[i].checked = ch;
}
}
function showResult(){
var chkbox = document.getElementsByName("id");
var id;
for(var i=0;i < chkbox.length; i++){
if(chkbox[i].checked){
id += (id==""?"":",") + chkbox[i].value;
}
}
alert(id);
}
</script>
</head>
<body>
<input type="checkbox" id="selectAll" οnclick="javascript:selectAllID();"/>
全选
<input type="button" value="显示结果" οnclick="showResult()"><br>
<input type="checkbox" name="id" value="4256" >选项1<br>
<input type="checkbox" name="id" value="4546" >选项2<br>
<input type="checkbox" name="id" value="4556" >选项3<br>
<input type="checkbox" name="id" value="4456" >选项4<br>
<input type="checkbox" name="id" value="356" >选项5<br>
<input type="checkbox" name="id" value="4256" >选项6<br>
<input type="checkbox" name="id" value="4356" >选项7<br>
<input type="checkbox" name="id" value="156" >选项8<br>
<input type="checkbox" name="id" value="456" >选项9<br>
<input type="checkbox" name="id" value="4346" >选项10<br>
<input type="checkbox" name="id" value="8756" >选项11
</body>
</html>
<head>
<script type="text/javascript">
function selectAllID(){
var allSel = document.getElementsByName("id");
var selectAll = document.getElementById("selectAll");
var ch = selectAll.checked;
for(var i=0;i<allSel.length;i++){
allSel[i].checked = ch;
}
}
function showResult(){
var chkbox = document.getElementsByName("id");
var id;
for(var i=0;i < chkbox.length; i++){
if(chkbox[i].checked){
id += (id==""?"":",") + chkbox[i].value;
}
}
alert(id);
}
</script>
</head>
<body>
<input type="checkbox" id="selectAll" οnclick="javascript:selectAllID();"/>
全选
<input type="button" value="显示结果" οnclick="showResult()"><br>
<input type="checkbox" name="id" value="4256" >选项1<br>
<input type="checkbox" name="id" value="4546" >选项2<br>
<input type="checkbox" name="id" value="4556" >选项3<br>
<input type="checkbox" name="id" value="4456" >选项4<br>
<input type="checkbox" name="id" value="356" >选项5<br>
<input type="checkbox" name="id" value="4256" >选项6<br>
<input type="checkbox" name="id" value="4356" >选项7<br>
<input type="checkbox" name="id" value="156" >选项8<br>
<input type="checkbox" name="id" value="456" >选项9<br>
<input type="checkbox" name="id" value="4346" >选项10<br>
<input type="checkbox" name="id" value="8756" >选项11
</body>
</html>