|
以下代码功能是:复选框(checkbox)选中一项,这一项的表格背景变颜色,可我是通过循环
<tr>
<td><input type="checkbox" id="check4"></td>
<td>?</td>
<td>?</td>
<td>?</td>
<td>?</td>
</tr>
获取数据,不能像固定的表格那样check1、check2……应怎样写代码,达到这种效果?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>New Page 1</title>
<script>
function choiceColor(objChk,objTr){
if(objChk.checked == true) {
objTr.style.background = 'c0c0c0';
}else{
objTr.style.background ='white';
}
}
</script>
</head>
<body>
<table width="408" border=1 style="BORDER-COLLAPSE: collapse">
<tr onClick="choiceColor(check1,this)">
<td><input type="checkbox" id="check1"></td>
<td>?</td>
<td>?</td>
<td>?</td>
<td>?</td>
</tr>
<tr onClick="choiceColor(check2,this)">
<td><input type="checkbox" id="check2"></td>
<td>?</td>
<td>?</td>
<td>?</td>
<td>?</td>
</tr>
<tr onClick="choiceColor(check3,this)">
<td><input type="checkbox" id="check3"></td>
<td>?</td>
<td>?</td>
<td>?</td>
<td>?</td>
</tr>
<tr onClick="choiceColor(check4,this)">
<td><input type="checkbox" id="check4"></td>
<td>?</td>
<td>?</td>
<td>?</td>
<td>?</td>
</tr>
<tr onClick="choiceColor(check5,this)">
<td><input type="checkbox" id="check5"></td>
<td>?</td>
<td>?</td>
<td>?</td>
<td>?</td>
</tr>
</table>
</body>
</html> |
|