<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>查看复选框ID</title>
<script type="text/javascript">
function getCheckboxId(){//得到复选框ID的js函数
var c = document.getElementsByName('checkbox');
var counter = 0;
var idArray = new Array();//把ID放在数组里面
for(var i = 0;i<c.length;i++){
if(c[i].checked){
idArray[i]=c[i].value;
counter++;
}
}
if(counter ==0){
alert('请选择记录!');
return false;
}
alert(idArray);
}
function gotoCheckAll(){//选中或者取消全部选择项
if(document.getElementById("checkAll").checked){
var c = document.getElementsByName('checkbox');
for(var i = 0;i<c.length;i++){
c[i].checked ="checked";
}
}else{
var c = document.getElementsByName('checkbox');
for(var i = 0;i<c.length;i++){
c[i].checked ="";
}
}
}
</script>
</head>
<body>
<!--一个有几条数据的表格-->
<table width="100%" align="center" border="1" bordercolor="#adc9d7" bordercolordark="#FFFFFF" cellspacing="0"
cellpadding="0">
<tr>
<td width="5%" class="table_title" align="center">
<input type="checkbox" name="checkAll" id="checkAll" onclick="gotoCheckAll();" />
</td>
<td width="15%" class="table_title" align="center">
用户名
</td>
</tr>
<tr bgcolor="white">
<td align="center">
<input type="checkbox" name="checkbox" value="1" />
</td>
<td align="center">
ding1
</td>
</tr>
<tr bgcolor="white">
<td align="center">
<input type="checkbox" name="checkbox" value="2" />
</td>
<td align="center">
ding2
</td>
</tr>
<tr bgcolor="white">
<td align="center">
<input type="checkbox" name="checkbox" value="3" />
</td>
<td align="center">
ding3
</td>
</tr>
</table>
<br />
<center><input type="button" value="查看ID" onclick="getCheckboxId();"/></center>
</body>
</html>
posted on 2009-05-22 11:07
老丁 阅读(537)
评论(0) 编辑 收藏 所属分类:
html tag 、
js相关