parentNode.parentNode.parentNode...parentNode.rowIndex不过最好还是给tr加个id

解决方案 »

  1.   

    为什么说最好不要给tr加id呢?
      

  2.   

    parentNode.parentNode.parentNode...parentNode.rowIndex 
    这个东西我理解,但我在get()这里面传什么参数呢?
    是传get(this)吗?
    然后function get(this){
    alert(this.parentNode.parentNode.parentNode...parentNode.rowIndex);
    }
    对不起,我水平很菜,我这样试过了不行的啊
      

  3.   


    function get(_this){
    alert(_this.parentNode.parentNode.parentNode...parentNode.rowIndex);

    <table id=table1>
    <tr> </tr>
    <tr> </tr>
    <tr> <td> <table> <tr> <td> <a href=javescript:get(this); </td> </tr> </table> </td> </tr>
    </table> 
      

  4.   

    这个代码没有反映啊?function get(_this){
    alert(_this.parentNode.parentNode.parentNode...parentNode.rowIndex);
    } 这个里面的parentNode,是不是应该5个?为什么function get(_this),这里面参数要有下划线
      

  5.   

    <script>
    function get(_this){
    alert(_this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.rowIndex);
    }
    </script><table id=table1>
    <tr> </tr>
    <tr> </tr>
    <tr> <td> <table> <tr> <td> <a href="javascript:get(this)">asd</a> </td> </tr> </table> </td> </tr>
    </table> 
    这样还是没做用,哪位帮忙看一下,我是错在哪了呢非常感谢
      

  6.   

    <table id=table1>
    <tr> </tr>
    <tr> </tr>
    <tr> <td> <table> <tr> <td> <a  onclick="get(this)">aa</a> </td> </tr> </table> </td></tr>
    </table> 
    <script> 
    function get(_this){ 
    alert(_this.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.rowIndex); 

    </script>
      

  7.   

    你也可以用鼠标定位的方法,获取当前鼠标处于何位置,然后得到这个位置处的对象,在判断这个对象是不是超链接还是TD,就能准确获知当前在整个表格中处于第几行第几列,至于table加不加ID,都是无所谓的。