try something like
<script language="javascript">
var tr=null;function setColor()
{
  if (tr != null)
  {
tr.style.backgroundColor="";
tr = null;
  }
  
  var e = event.srcElement;
  e = e.parentElement;
  while (e != null && e.tagName != "TR")
e = e.parentElement;  if (e != null && e.tagName == "TR")
   tr = e;  if (tr != null)
tr.style.backgroundColor="red";
}
</script>
<table>
<tbody>
<tr onclick="setColor()">
 <td>hello</td><td>hello</td><td>hello</td>
</tr>
<tr onclick="setColor()">
 <td>hello</td><td>hello</td><td>hello</td>
</tr>
<tr onclick="setColor()">
 <td>hello</td><td><font size="12"><div>hello<div></font></td><td>hello</td>
</tr>
</tbody>
</table>

解决方案 »

  1.   

    function getTR(e)
    {
       if(e.tagName=="TR") return e
       e=e.parentElement
       if(e.tagName=="BODY") return null
       return getTR(e)
    }
    .....
    lastClickObject=getTR(event.srcElement)....
    如果你在<font>中定义了颜色/背景色,那么tr的颜色/背景色无法覆盖<font>中的设置
      

  2.   

    <html>
    <head>
    </head><xml id=testTable>
    <root>
    <tuple>
     <firstname>Dickensi </firstname>
     <lastname>Wen</lastname>
    </tuple>
    <tuple>
     <firstname>Steve</firstname>
     <lastname>Tao</lastname>
    </tuple>
    <tuple>
     <firstname>dfdsfsd</firstname>
     <lastname>dfsf</lastname>
    </tuple>
    </root>
    </xml><script>
    // load ur table from the xml
    var oOldCurTr = null;
    var bgColor = {select:"#cc7d8d",normal:"#ffffff"};function onLoadPage(){
      var oNodes = testTable.XMLDocument.selectNodes(".//tuple");
      var strInnerHTML = "<table cellpadding='0' cellspacing='0' onclick='onDKSMouseClick()'><TBODY>" ;
      for(var i=0; i<oNodes.length; i++){
         strInnerHTML += "<tr><td>";
         strInnerHTML += oNodes[i].selectSingleNode(".//firstname").text + "&nbsp&nbsp";
         strInnerHTML += "</td><td>"
         strInnerHTML += oNodes[i].selectSingleNode(".//lastname").text;
         strInnerHTML += "</td></tr>";
      }
      strInnerHTML += "</TBODY></table>" ;
      myTableContainer.innerHTML = strInnerHTML;}function onDKSMouseClick(){
      var oEle = event.srcElement;
      var oTr = getCurrentTr(oEle);
      if(oTr != null){
        if(oOldCurTr != null){
          oOldCurTr.bgColor = bgColor.normal;
        }
        oOldCurTr = oTr ;
        oTr.bgColor = bgColor.select;
      }
    }function getCurrentTr(oEle){
     var oTrItem = oEle;
     while(oTrItem.tagName.toUpperCase() != "TR"){
        oTrItem = oTrItem.parentElement;
        if(oTrItem == null){
          break;
        }
     }
     return oTrItem;
    }
    </script><body onload="onLoadPage()"><table>
    <tr><td id=myTableContainer>dfdf</td></tr>
    </table></body>
    </html>
    未经测试,可能有bug
      

  3.   

    我碰到过类似问题。
    事情出在冒泡机制上。你用连续的两个parentNode并不能解决问题。
    即使你将事件处理器设定在TR一级,事件仍然是由最底层或者说最重孙辈的娃娃们触发,然后向上传直到碰到处理器。
    因为触发事件的元素并不一定每次都在同一个层次。每一个可以接收事件的元素都可能是SrcElement,这取决于你究竟按在哪里了。例如,如果TD里有个元素<br>,这个BR都有可能触发事件;如果TD内完全是空的,事件由TD触发。我打赌你一定想在附加事件的时候加上个this参数,可惜加不上:-)))
    解决的办法有两个:
    1. 设定函数FoundTheTR();该函数用来向上追溯娃娃的老爹爷爷们,直到这个碰到个TR元素为止。这个方法是偶用过的,包试包灵。
    2。还没有时间去发掘,大约就是找个办法把那个this给塞进去。
      

  4.   

    你那个font里面包个div,div里面又鬼知道包什么,娃娃的娃娃的娃娃嘿嘿
    用函数逐级追溯吧,别愁了。
      

  5.   

    另外,整行记录变深你用font?
    在TR或者TD级别设置style!
      

  6.   

    function MoverTR(){
    var oTR=FoundTR(event.srcElement);
    if(!oTR)return false;
    oTR.style.backgroundColor=top.cC2;
    return true;
    }
    function FoundTR(oSRC){
    var i=0;
    while(oSRC.tagName!="TR"){
    i++;if(i>10){alert('出现严重兼容问题!');return null;}
    oSRC=oSRC.parentNode;
    }
    return oSRC;
    }
      

  7.   

    并不是没有谁可以解决你的问题,只是他们的方法和你的不一样而已.
    我觉得你对文字的定义放到<td>里面去就行了
      <td nowrap style="color:#000080;font-size:25pt">gfgdfg</td>
      

  8.   

    给分了!!!!解决了!!!
    多谢lansajf(海)!!!!!!!!!!!!!!!!!!!!!!!!!!