<input type="button" id="startButton" name="Button" value="开始" style="POSITION: absolute;">
<script>
function getDim(el){
var rd = {x:0,y:0}
do{
rd.x += el.offsetLeft
rd.y += el.offsetTop
el = el.offsetParent
} while(el)
return rd
}</script><span id=MySpan>获得非定位元素的坐标值</span><script>
mySpanDim = getDim(document.all.startButton)
alert("startButton : x:" + mySpanDim.x + ", y:" + mySpanDim.y)
</script>

解决方案 »

  1.   

    posLeft:
    This property reflects the value of the Cascading Style Sheets (CSS) left attribute for positioned items. This property always returns zero for nonpositioned items because "left" has meaning only when the object is positioned. If the left attribute is not set, the posLeft property returns zero. Use the offsetLeft property to calculate actual positions within the document area.Setting this property changes the value of the left position but leaves the units designator for the property unchanged.Unlike the left property, the posLeft property value is a floating-point number, not a string.For more information about how to access the dimension and location of elements on the page through the Dynamic HTML (DHTML) Document Object Model (DOM), see Measuring Element Dimension and Location.
      

  2.   

    //JS取得控件的绝对位置
    <script language="Javascript">
    function getIE(e){
      var t=e.offsetTop;
      var l=e.offsetLeft;
      while(e=e.offsetParent){
        t+=e.offsetTop;
        l+=e.offsetLeft;
        }
      alert("top="+t+"\nleft="+l);
      }
    </script>//VBScript
    <script language="VBScript"><!--
    function getIE()
      dim t,l,a,b
      set a=document.all.img1
      t=document.all.img1.offsetTop
      l=document.all.img1.offsetLeft
      while a.tagName<>"BODY"
        set a = a.offsetParent
        t=t+a.offsetTop
        l=l+a.offsetLeft
      wend
      msgbox "top="&t&chr(13)&"left="&l,64,"得到控件的位置"
    end function
    --></script>