checkbox的全选反选(兼容IE、Firefox)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<script language="javascript">
function selectIt(action,frm,name){
var es= frm.elements[name];
if (es.length)
for(var i=0,e;e = es[i],i<es.length;i++)
e.checked=(action)?1:(!e.checked);
else
es.checked=(action)?1:(!es.checked);
}
</script>
</head>
<body>
<form name="bdkey" id="bdkey">
<p class="STYLE1">
全 选
<input type="checkbox" name="selectAll" value="checkbox" onClick="selectIt(1,this.form,'checkbox')"><br>
反 选
<input type="checkbox" name="invest" value="checkbox" onClick="selectIt(0,this.form,'checkbox')"><br>
Item1
<input type="checkbox" name="checkbox" value="checkbox">
<br>
Item2
<input type="checkbox" name="checkbox" value="checkbox"><br>
Item3
<input type="checkbox" name="checkbox" value="checkbox"><br>
Item4
<input type="checkbox" name="checkbox" value="checkbox"><br>
Item5
<input type="checkbox" name="checkbox" value="checkbox">
</p>
</form>
</body>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<script language="javascript">
function selectIt(action,frm,name){
var es= frm.elements[name];
if (es.length)
for(var i=0,e;e = es[i],i<es.length;i++)
e.checked=(action)?1:(!e.checked);
else
es.checked=(action)?1:(!es.checked);
}
</script>
</head>
<body>
<form name="bdkey" id="bdkey">
<p class="STYLE1">
全 选
<input type="checkbox" name="selectAll" value="checkbox" onClick="selectIt(1,this.form,'checkbox')"><br>
反 选
<input type="checkbox" name="invest" value="checkbox" onClick="selectIt(0,this.form,'checkbox')"><br>
Item1
<input type="checkbox" name="checkbox" value="checkbox">
<br>
Item2
<input type="checkbox" name="checkbox" value="checkbox"><br>
Item3
<input type="checkbox" name="checkbox" value="checkbox"><br>
Item4
<input type="checkbox" name="checkbox" value="checkbox"><br>
Item5
<input type="checkbox" name="checkbox" value="checkbox">
</p>
</form>
</body>
posted on 2007-11-29 15:39 oldmanwang 阅读(1405) 评论(0) 编辑 收藏 举报