<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">
var __tr = null;
function mm(tr)
{
    //这两行代码实现换色
    if(__tr) __tr.style.backgroundColor="";
    __tr=tr; __tr.style.backgroundColor="red";
    //下面的代码实现选中的效果
    var a = tr.getElementsByTagName("INPUT");
    for(var i=0; i<a.length; i++) a[i].click();
}
</SCRIPT>

解决方案 »

  1.   

    我是这么实现的,梅大哥,帮我看看有无问题?<table border="1" width="200">
    <tr id="a0" onclick="show(this,1)">
    <td><input id="1" type="radio" name="a"></td><td>123</td></tr>
    <tr id="a1" onclick="show(this,2)">
    <td><input id="2" type="radio" name="a"></td><td>456</td></tr>
    </table>
    <script language=javascript>
    function show(obj,n)
    {
    for (i=0;i<a.length;i++){
       document.getElementById("a"+i).style.backgroundColor="#FFFFFF"
         }   if(document.getElementById(n).checked == false){
        document.getElementById(n).checked = true
        obj.style.backgroundColor="#D7E8F8"
    }
    }
    </script>
      

  2.   

    好了,我自己搞定了,我是想要这种效果~谢谢大家!<table border="1" width="200">
    <tr id="a0" onclick="show(this,1)">
    <td><input id="1" type="radio" name="a"></td><td>123</td></tr>
    <tr id="a1" onclick="show(this,2)">
    <td><input id="2" type="radio" name="a"></td><td>456</td></tr>
    </table>
    <script language=javascript>
    function show(obj,n)
    {
    for (i=0;i<a.length;i++){
       document.getElementById("a"+i).style.backgroundColor="#FFFFFF"
         }   if(document.getElementById(n).checked == false){
        document.getElementById(n).checked = true
        obj.style.backgroundColor="#D7E8F8"
    }
    }
    </script>