function Point(iX, iY){
this.x = iX;
this.y = iY;
}function fGetXY(aTag){
  var oTmp = aTag;
  var pt = new Point(0,0);
  do {
   pt.x += oTmp.offsetLeft;
   pt.y += oTmp.offsetTop;
   oTmp = oTmp.offsetParent;
  } while(oTmp.tagName!="BODY");
  return pt;
}

解决方案 »

  1.   

    这是一个例子
    --------------------------
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <script language="javascript">
    function Point(iX, iY){
    this.x = iX;
    this.y = iY;
    }function fGetXY(aTag){ //传入目标对象
      var oTmp = aTag;
      var pt = new Point(0,0);
      do {
       pt.x += oTmp.offsetLeft;
       pt.y += oTmp.offsetTop;
       oTmp = oTmp.offsetParent;
      } while(oTmp.tagName!="BODY");
      return pt;
    }function showPosition(obj){
    var pt=fGetXY(obj);
    alert('X坐标为:'+pt.x+'\nY坐标为:'+pt.y);
    }
    </script>
    </head><body>
    <table width="100%" border="0" cellspacing="50" cellpadding="1">
      <tr>
        <td width="33%"><input name="button" type="button" value="看看我的坐标" onclick="showPosition(this)"/></td>
        <td width="34%"><input name="button2" type="button" value="看看我的坐标" onclick="showPosition(this)"/></td>
        <td width="33%"><input name="button3" type="button" value="看看我的坐标" onclick="showPosition(this)"/></td>
      </tr>
      <tr>
        <td><input name="button7" type="button" value="看看我的坐标" onclick="showPosition(this)"/></td>
        <td><input name="button6" type="button" value="看看我的坐标" onclick="showPosition(this)"/></td>
        <td><input name="button4" type="button" value="看看我的坐标" onclick="showPosition(this)"/></td>
      </tr>
      <tr>
        <td><input name="button8" type="button" value="看看我的坐标" onclick="showPosition(this)"/></td>
        <td><input name="button62" type="button" value="看看我的坐标" onclick="showPosition(this)"/></td>
        <td><input name="button5" type="button" value="看看我的坐标" onclick="showPosition(this)"/></td>
      </tr>
    </table>
    </body>
    </html>
      

  2.   

    在asp.net后代码(c#)中如何写:将按钮id值传到js的函数中;
    调用我知道.但showPosition(obj)中的obj如何写
      

  3.   

    不明白你的意思.<Tag id="xxx" /><script language="javascript">showPosition(document.getElementById('xxx'))</script>这样看懂了吗