项目里边用到了用JavaScript遍历一个表格里全部的CheckBox控件,并且判断是否已经选中的功能并取其选中值的功能,从网上找到了如下代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language=javascript>
function BianLi()
{
var oo = document.getElementById("tb").getElementsByTagName("input");
for(var k = 0, len = oo.length; k < len; k++)
{
var t = oo[k].type;
if(t=="text" || t=="radio")
alert("类型:"+t+"/t值:"+oo[k].value);
}
}
</script>
<table id="tb">
<tr>
<td><input type="text" value="**1"/></td>
<td><input type="radio" name="1" value="11"/>
a</td>
<td></td>
<td><input type="radio" name="1" value="13"/>
c</td>
<tr>
<tr>
<td><input type="text" value="**2"/></td>
<td><input type="radio" name="1" value="12"/>
a</td>
<td><input type="radio" name="1" value="22"/>
b</td>
<td></td>
<tr>
<!----下面为不规则行------>
<tr>
<td><input type="text" value="**3"/></td>
<td colspan='3'><input type="radio" name="1" value="31"/>
a</td>
<tr>
</table>
<input type="button" value="遍历" οnclick="BianLi()"/>
<label></label>
</body></html>