<script language="javaScript">
//全选或全部不选
function checkall() {
var isChecked=(document.form1.checkAll.checked == true);
var elements_all=document.form1.elements;
for(i=0;i<elements_all.length;i++) {
var element=elements_all[i];
if(element.type=="checkbox") {
element.checked=isChecked;
}
}
}
//是否有checkbox被选中
function anyChecked() {
var elements_any=document.form1.elements;
for(i=0;i<elements_any.length;i++) {
var element=elements_any[i];
if(element.checked == true) {
return true;
}
}
return false;
}
</script>
<form name="form1" Method="post" action="" onsubmit="return anyChecked()">
全选:<input type="checkbox" id="checkAll"onclick="checkall()" />
多项选择框列表:
<input type="checkbox" name="cb" value="1"/>
<input type="checkbox" name="cb" value="2"/>
<input type="checkbox" name="cb" value="3"/>
<input name="Submit" type="submit" value="submit">
</form>
[url]http://wjt276.iteye.com/blog/455109[/url]