点击其中一行,我怎么来改变这行的某些属性?用this来引用当前行
<table name="thistab">
<tr onclick="this.bgcolor='#111111'">
...
</tr>
<tr onclick="this.xxx=xxx">
...
</tr>
<tr>
...
</tr>
...
</tab>

解决方案 »

  1.   

    <div align="center">
    <table id="tbl" border="1" cellpadding="0" style="border-collapse: collapse" width="98%">
    <tr height="20">
    <td>1</td>
    <td>2</td>
    <td>3</td>
    </tr>
    <tr height="20">
    <td></td>
    <td></td>
    <td></td>
    </tr>
    <tr height="20">
    <td></td>
    <td></td>
    <td></td>
    </tr>
    <tr height="20">
    <td></td>
    <td></td>
    <td></td>
    </tr>
    </table>
    </div><script language="javascript">
    <!--
    function changeColor(rowIndex,strColor)
    {
    var o = tbl.childNodes(0).childNodes;
    o[rowIndex].bgColor = strColor;
    }changeColor(0,"red");
    //-->
    </script>索引从0开始  第一行是0
      

  2.   

    也可以用table的rowIndex属性和rows属性吧
      

  3.   

    <script>
    document.write("<table border='1' cellpadding='3' cellspacing='0' width='95%' bgcolor='#EEEEEE' bordercolordark='#FFFFFF' bordercolorlight='#999999'>");
    for(iIndex=0;iIndex<10;iIndex++)
    {
    document.write("<tr><td width='100%' id='Td"+iIndex+"' onclick='this.style.backgroundColor=\"#FFFFFF\";'>&nbsp;</td></tr>");
    }
    document.write("</table>");
    </script>
    如果已经输出onclick事件可以用:
    document.getElementById(\"Td\"+iIndex).style.backgroundColor=\"#FFFFFF\";来访问.
      

  4.   

    最好的方法是我的方法: 
    利用src.parentElement.sectionRowIndex就可以直接得到点击的行 
    代码如下:
    <script>
    var curRow;
    function clickontb()
    {
       src    = event.srcElement;
       if(MyTD.rows[curRow])
       {
           MyTD.rows[curRow].style.backgroundColor = "#FFFFFF";
       }
       curRow = src.parentElement.sectionRowIndex ;
       if(MyTD.rows[curRow])
       {
           MyTD.rows[curRow].style.backgroundColor = "#FF0000";
       }
    }
    </script><table id="MyTD" onClick="clickontb()" border="1px #000000 solid" style="font-size:12px;cursor:hand">
    <tr>
    <td>1111111111</td>
    <td>1111122222</td>
    </tr>
    <tr>
    <td>2222211111</td>
    <td>2222222222</td>
    </tr>
    <tr>
    <td>3333311111</td>
    <td>3333322222</td>
    </tr>
    </table>
      

  5.   

    <script>
    var curRow;
    function clickontb()
    {
       src    = event.srcElement;
       while(src.tagName!="TR")src=src.parentElement;
       src.style.backgroundColor = "#FF0000";   if(MyTD.rows[curRow])MyTD.rows[curRow].style.backgroundColor = "#FFFFFF";
       curRow=src.rowIndex;
    }
    </script><table id="MyTD" onClick="clickontb()" border="1px #000000 solid" style="font-size:12px;cursor:hand">
    <tr>
    <td>1111111111</td>
    <td>1111122222</td>
    </tr>
    <tr>
    <td>2222211111</td>
    <td>2222222222</td>
    </tr>
    <tr>
    <td>3333311111</td>
    <td>3333322222</td>
    </tr>
    </table>
      

  6.   

    <script language="JavaScript">
    function aa(obj){
    for (var i = 0 ; i < obj.cells.length ; i++)
    {
    alert(obj.cells(i).sytle.bgcolor="#666666")
    }
    }
    </script>
    <body>
    <table width="200" border="1" cellspacing="0" cellpadding="0">
      <tr onMouseOver="aa(this)">
        <td bgcolor="#999999">AAAA</td>
        <td bgcolor="#999999">BBBB</td>
        <td bgcolor="#999999">CCCC</td>
      </tr>
    </table></body>
      

  7.   

    已经解决,用rows属性。点击其中某行得同时,还要将上次点击得行还原颜色,因此 ploughsky(至少还有我) 方法不好用,其他得都可以,放分!