<table>
<tr onclick="alert('这是第'+this.rowIndex+'行')">
<td>ghd</td>hfdhd<td>hdhdf</td>hdgd<td>hdfhg</td><td>hgdhd</td></tr>
<tr onclick="alert('这是第'+this.rowIndex+'行')>
<td>ghd</td>hfdhd<td>hdhdf</td>hdgd<td>hdfhg</td><td>hgdhd</td></tr>
<tr onclick="alert('这是第'+this.rowIndex+'行')>
<td>ghd</td>hfdhd<td>hdhdf</td>hdgd<td>hdfhg</td><td>hgdhd</td></tr>
<tr onclick="alert('这是第'+this.rowIndex+'行')>
<td>ghd</td>hfdhd<td>hdhdf</td>hdgd<td>hdfhg</td><td>hgdhd</td></tr>
</table>rowIndex从0开始,就是行号!

解决方案 »

  1.   

    不行,我“onclick”是在<td>标记中。“this.rowIndex”显示为“undefine"
      

  2.   

    <table>
    <tr>
    <td onclick="alert('这是第'+this.parentNode.rowIndex+'行\n第'+this.cellIndex+'列)">ghd</td>hfdhd<td onclick="alert('这是第'+this.parentNode.rowIndex+'行\n第'+this.cellIndex+'列)">hdhdf</td>hdgd<td>hdfhg</td><td onclick="alert('这是第'+this.parentNode.rowIndex+'行\n第'+this.cellIndex+'列)">hgdhd</td></tr>
    <tr >
    <td onclick="alert('这是第'+this.parentNode.rowIndex+'行\n第'+this.cellIndex+'列)">ghd</td>hfdhd<td onclick="alert('这是第'+this.parentNode.rowIndex+'行\n第'+this.cellIndex+'列)">hdhdf</td>hdgd<td onclick="alert('这是第'+this.parentNode.rowIndex+'行\n第'+this.cellIndex+'列)">hdfhg</td><td onclick="alert('这是第'+this.parentNode.rowIndex+'行\n第'+this.cellIndex+'列)">hgdhd</td></tr></table>那就改为 onclick="alert('这是第'+this.parentNode.rowIndex+'行\n第'+this.cellIndex+'列')
      

  3.   

    请问有没有学习”javascript“的好书,我刚学。
      

  4.   

    rowIndex是行属性,cellIndex是单元格属性!所以不能再单元各种用rowIndex
      

  5.   

    to  naci007(阿淼):
    你搜索一下教程,多的很。我已经无数遍回答过别人这种问题。入门击的教材:javascript网页彻底研究---陈会安   人民邮电出版社   标旗出版股份有限公司差不多之后看:javascript完全手册  --电子工业出版社 红皮书javascript使用手册  --机械工业出版社  黑皮书  很经典的!我就靠这几本书起家的!
      

  6.   

    等你学得差不多就可以下在一个电子稳当,随时查阅。上微软网站找faq里面有连接!你看看就有了!不会的给我发短信!