<!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 getRadioId(){//得到单选框ID的js函数
var c = document.getElementsByName('radio');
var counter = 0;
var j;
for(var i = 0;i<c.length;i++){
if(c[i].checked){
counter++;
j = i;
}
}
if(counter ==0){
alert('请选择记录!');
return false;
}
var id = c[j].value;
alert(id);
}
</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">
选择
</td>
<td width="15%" class="table_title" align="center">
用户名
</td>
</tr>
<tr bgcolor="white">
<td align="center">
<input type="radio" name="radio" value="1" />
</td>
<td align="center">
ding1
</td>
</tr>
<tr bgcolor="white">
<td align="center">
<input type="radio" name="radio" value="2" />
</td>
<td align="center">
ding2
</td>
</tr>
<tr bgcolor="white">
<td align="center">
<input type="radio" name="radio" value="3" />
</td>
<td align="center">
ding3
</td>
</tr>
</table>
<br />
<center><input type="button" value="查看ID" onclick="getRadioId();"/></center>
</body>
</html>
posted on 2009-05-22 11:06
老丁 阅读(868)
评论(1) 编辑 收藏 所属分类:
html tag 、
js相关