var row=obj.rowIndex;
var cell=obj.cellIndex;
前提需要得到该行或者列对象

解决方案 »

  1.   

    <html>
    <head><script language=javascript>
    function a(o){
    var col=o.parentNode.id;
    var row=o.parentNode.parentNode.id;
    alert("col:"+col+";row:"+row);
    }
    </script>
    </head>
    <body>
    <table border=1 width="100">
    <tr id="1"><td id="1" ><a href="#" onclick="a(this)">1</a></td><td id="2"><a href="#" onclick="a(this)">2</a></td></tr>
    <tr id="2"><td id="1"><a href="#" onclick="a(this)">3</a></td><td id="2"><a href="#" onclick="a(this)">4</a></td></tr>
    <tr id="3"><td id="1"><a href="#" onclick="a(this)">5</a></td><td id="2"><a href="#" onclick="a(this)">6</a></td></tr>
    <tr id="4"><td id="1"><a href="#" onclick="a(this)">7</a></td><td id="2"><a href="#" onclick="a(this)">8</a></td></tr>
    </table>
    </body>
    </html>
      

  2.   

    <html>
    <head>
    <title>new page</title>
    <script language=javascript>
    function a(obj){
    var col=obj.parentNode.cellIndex;//列索引,初始值为0
    var row=obj.parentNode.parentNode.rowIndex;//行索引,初始值为0
    alert("col:"+col+";row:"+row);
    }
    </script>
    </head>
    <body>
    <table border=1 width="100">
    <tr>
    <td><a href="#" onclick="a(this)">1</a></td>
    <td><a href="#" onclick="a(this)">2</a></td>
    </tr>
    <tr>
    <td><a href="#" onclick="a(this)">3</a></td>
    <td><a href="#" onclick="a(this)">4</a></td>
    </tr>
    <tr>
    <td><a href="#" onclick="a(this)">5</a></td>
    <td><a href="#" onclick="a(this)">6</a></td>
    </tr>
    <tr>
    <td><a href="#" onclick="a(this)">7</a></td>
    <td><a href="#" onclick="a(this)">8</a></td>
    </tr>
    </table>
    </body>
    </html>