<table width="100%" border="1">
  <tr onclick=alert(this.rowIndex)>
    <td>&nbsp;</td>
  </tr>
  <tr onclick=alert(this.rowIndex)>
    <td>&nbsp;</td>
  </tr>
  <tr onclick=alert(this.rowIndex)>
    <td>&nbsp;</td>
  </tr>
  <tr onclick=alert(this.rowIndex)>
    <td>&nbsp;</td>
  </tr>
  <tr onclick=alert(this.rowIndex)>
    <td>&nbsp;</td>
  </tr>
</table>

解决方案 »

  1.   

    <script language="javascript">
    function fx(v){
    var target=document.getElementsByTagName("tr")
    for(var i=0;i<target.length;i++)
    if(v==target[i])
    alert("行号:"+parseInt(i+1))
    }
    </script>
    <table width="100%" border="1" cellspacing="0" cellpadding="0">
      <tr onclick="fx(this)">
        <td>&nbsp;</td>
      </tr>
      <tr onclick="fx(this)">
        <td>&nbsp;</td>
      </tr>
      <tr onclick="fx(this)">
        <td>&nbsp;</td>
      </tr>
      <tr onclick="fx(this)">
        <td>&nbsp;</td>
      </tr>
      <tr onclick="fx(this)">
        <td>&nbsp;</td>
      </tr>
    </table>
      

  2.   

    既然行是this.rowIndex,我估计列号是this.colIndex
      

  3.   

    我测试时为什么出现“undefinde”啊?
      

  4.   

    <table width="100%" border="1" cellspacing="0" cellpadding="0">
      <tr>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
      </tr>
      <tr>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
      </tr>
      <tr>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
      </tr>
      <tr>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
      </tr>
      <tr>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
        <td  onclick="alert(this.cellIndex)">&nbsp;</td>
      </tr>
    </table>