87,922
社区成员
发帖
与我相关
我的任务
分享
<table width="150" border="1" cellpadding="1" cellspacing="1">
<tr>
<td><input type="checkbox" name="checkbox" value="01"></td>
<td>11</td>
<td>12</td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox" value="02"></td>
<td>21</td>
<td>22</td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox" value="03"></td>
<td>31</td>
<td>32</td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox" value="04"></td>
<td>41</td>
<td>42</td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox" value="05"></td>
<td>51</td>
<td>52</td>
</tr>
</table>
$(input[name="checkbox"]').click(function(){
var tr = $(this).paren('tr');
$(this).attr('checked') ? tr.attr('bgColor', '#CCCCCC') : tr.attr('bgColor', '');
});
<script language="javascript">
function d(e){
var o=e.target||event.srcElement;
if(o.type=="checkbox")o.parentNode.parentNode.bgColor=o.checked?'#CCCCCC':'';
}
</script>
<table width="150" border="1" cellpadding="1" cellspacing="1" onclick="d(event)">
<tr>
<td><input type="checkbox"></td>
<td>11</td>
<td>12</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td>21</td>
<td>22</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td>31</td>
<td>32</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td>41</td>
<td>42</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td>51</td>
<td>52</td>
</tr>
</table>
<script>
function checkit(evt){
var obj = window.event?event.srcElement:evt.target;
obj.parentNode.parentNode.style.backgroundColor= obj.checked?'#CCC':'#FFF';
}
window.onload = function(){
var ck = document.getElementsByName("checkbox");
for(var i=0;i<ck.length;i++) ck[i].onclick = checkit;
}
</script>
<table width="150" border="1" cellpadding="1" cellspacing="1">
<tr>
<td><input type="checkbox" name="checkbox" value="01"></td>
<td>11</td>
<td>12</td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox" value="02"></td>
<td>21</td>
<td>22</td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox" value="03"></td>
<td>31</td>
<td>32</td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox" value="04"></td>
<td>41</td>
<td>42</td>
</tr>
<tr>
<td><input type="checkbox" name="checkbox" value="05"></td>
<td>51</td>
<td>52</td>
</tr>
</table>
$(input[name="checkbox"]').click(function(){
var tr = $(this).paren('tr');
$(this).val() ? tr.attr('bgColor', '#CCCCCC') : tr.attr('bgColor', ');
});