<table border="1" width="200">
<tr onMouseOver="this.style.backgroundColor='#D7E8F8'" onMouseOut="this.style.backgroundColor='#FFFFFF'" onclick="this.childNodes[0].childNodes[0].checked=true">
<td><input type="checkbox" name="a"></td><td>123</td></tr>
<tr onMouseOver="this.style.backgroundColor='#D7E8F8'" onMouseOut="this.style.backgroundColor='#FFFFFF'" onclick="this.childNodes[0].childNodes[0].checked=true">
<td><input type="checkbox" name="a"></td><td>456</td></tr>
</table>
<tr onMouseOver="this.style.backgroundColor='#D7E8F8'" onMouseOut="this.style.backgroundColor='#FFFFFF'" onclick="this.childNodes[0].childNodes[0].checked=true">
<td><input type="checkbox" name="a"></td><td>123</td></tr>
<tr onMouseOver="this.style.backgroundColor='#D7E8F8'" onMouseOut="this.style.backgroundColor='#FFFFFF'" onclick="this.childNodes[0].childNodes[0].checked=true">
<td><input type="checkbox" name="a"></td><td>456</td></tr>
</table>
<tr onMouseOver="this.style.backgroundColor='#D7E8F8'" onMouseOut="this.style.backgroundColor='#FFFFFF'" onclick="show(this.childNodes[0].childNodes[0])">
<td><input type="checkbox" name="a"></td><td>123</td></tr>
<tr onMouseOver="this.style.backgroundColor='#D7E8F8'" onMouseOut="this.style.backgroundColor='#FFFFFF'" onclick="show(this.childNodes[0].childNodes[0])">
<td><input type="checkbox" name="a"></td><td>456</td></tr>
</table>
<script language=javascript>
function show(obj)
{
if(obj.checked==true)
{
obj.checked=false;
}
else
{
obj.checked=true;
}
}
</script>
<table border="1" width="200">
<tr onclick="if(document.getElementById('1').checked == true){document.getElementById('1').checked = false;this.style.backgroundColor='#D7E8F8'}else{document.getElementById('1').checked = true;this.style.backgroundColor='#F00';}" onMouseOver="if(document.getElementById('1').checked != true) this.style.backgroundColor='#D7E8F8'" onMouseOut="if(document.getElementById('1').checked != true) this.style.backgroundColor='#FFFFFF'">
<td><input id="1" type="checkbox" name="a"></td><td>123</td></tr>
<tr onclick="if(document.getElementById('2').checked == true){document.getElementById('2').checked = false;this.style.backgroundColor='#D7E8F8'}else{document.getElementById('2').checked = true;this.style.backgroundColor='#F00';}" onMouseOver="if(document.getElementById('2').checked != true) this.style.backgroundColor='#D7E8F8'" onMouseOut="if(document.getElementById('2').checked != true) this.style.backgroundColor='#FFFFFF'">
<td><input id="2" type="checkbox" name="a"></td><td>456</td></tr>
<tr onclick="if(document.getElementById('3').checked == true){document.getElementById('3').checked = false;this.style.backgroundColor='#D7E8F8'}else{document.getElementById('3').checked = true;this.style.backgroundColor='#F00';}" onMouseOver="if(document.getElementById('3').checked != true) this.style.backgroundColor='#D7E8F8'" onMouseOut="if(document.getElementById('3').checked != true) this.style.backgroundColor='#FFFFFF'">
<td><input id="3" type="checkbox" name="a"></td><td>456</td></tr>
<tr onclick="if(document.getElementById('4').checked == true){document.getElementById('4').checked = false;this.style.backgroundColor='#D7E8F8'}else{document.getElementById('4').checked = true;this.style.backgroundColor='#F00';}" onMouseOver="if(document.getElementById('4').checked != true) this.style.backgroundColor='#D7E8F8'" onMouseOut="if(document.getElementById('4').checked != true) this.style.backgroundColor='#FFFFFF'">
<td><input id="4" type="checkbox" name="a"></td><td>456</td></tr>
</table>
<tr onclick="if(document.getElementById('1').checked == true){document.getElementById('1').checked = false;this.style.backgroundColor='#FFFFFF'}else{document.getElementById('1').checked = true;this.style.backgroundColor='#F00';}">
<td><input id="1" type="radio" name="a"></td><td>123</td></tr>
<tr onclick="if(document.getElementById('2').checked == true){document.getElementById('2').checked = false;this.style.backgroundColor='#FFFFFF'}else{document.getElementById('2').checked = true;this.style.backgroundColor='#F00';}">
<td><input id="2" type="radio" name="a"></td><td>456</td></tr>
</table>---这样换成radio类型的就不行了,该怎么改呢???
<tr onclick="if(document.getElementById('1').checked == true){document.getElementById('1').checked = false;this.style.backgroundColor='#FFFFFF'}else{document.getElementById('1').checked = true;this.style.backgroundColor='#F00';}">
<td><input id="1" type="radio" name="a1"></td><td>123</td></tr>
<tr onclick="if(document.getElementById('2').checked == true){document.getElementById('2').checked = false;this.style.backgroundColor='#FFFFFF'}else{document.getElementById('2').checked = true;this.style.backgroundColor='#F00';}">
<td><input id="2" type="radio" name="a2"></td><td>456</td></tr>
</table>
,再点一下把checkbox勾去掉,表格变成原来的颜色.
------------------------------------------------
<table border="1" width="200">
<tr onclick="mm(this)">
<td><input id="1" type="checkbox" name="a"></td><td>123</td>
</tr>
<tr onclick="mm(this)">
<td><input id="2" type="checkbox" name="a"></td><td>456</td>
</tr>
</table>
<SCRIPT LANGUAGE="JavaScript">
function mm(tr)
{
var me = event.srcElement;
if(event.srcElement.tagName!="INPUT")
{
var a = tr.getElementsByTagName("INPUT");
for(var i=0; i<a.length; i++)
if(a[i].name=="a"){a[i].checked=!a[i].checked;me=a[i];break;}
}
tr.style.backgroundColor= me.checked ? "red" : "";
}
</SCRIPT>
<tr onclick="mm(this)">
<td><input id="1" type="checkbox" name="a"></td><td>123</td>
</tr>
<tr onclick="mm(this)">
<td><input id="2" type="checkbox" name="a"></td><td>456</td>
</tr>
</table>
<SCRIPT LANGUAGE="JavaScript">
//以下改自meizz(梅花雪)提供的函数,但比他的高效。
function mm(tr)
{
var me = event.srcElement;
if(me.tagName!="INPUT")
{
var me = tr.firstChild.firstChild;
me.checked=!me.checked;
}
tr.style.backgroundColor= me.checked ? "blue" : "";
}
</SCRIPT>