新闻详情

如何取得控件的绝对位置

3316 2009/5/18
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>标题页</title>
    <script language="javascript">
    function getAddress(e)
    {
       var t=e.offsetTop;
       var l=e.offsetLeft;
       while(e=e.offsetParent)
       {
          t+=e.offsetTop;  //获取X坐标
          l+=e.offsetLeft; //获取Y坐标
       }
       alert("x坐标="+t+"   y坐标为="+l);
    }
    </script>
</head>
<body>
<input id="Button1" type="button" value="坐标" onClick="getAddress(this)" />
</body>
</html>

相关资讯

18973218026
返回顶部