//得到控件的绝对位置
function getPos(obj)
{
    var pos = new Array();
    var t=obj.offsetTop;
    var l=obj.offsetLeft;
    while(obj=obj.offsetParent)
    {
        t+=obj.offsetTop;
        l+=obj.offsetLeft;
    }
    pos[0] = t;
    pos[1] = l;
    return pos;
}
alert(getPos(txt)[0]);
alert(getPos(txt)[1]);<input type=text id=txt>

解决方案 »

  1.   

    <body onload="alert('top:'+document.all.txt.offsetTop+'\n\n'+'left:'+document.all.txt.offsetLeft);">
    <input type=text id=txt>
    </body>就是offsetTop
        offsetLeft
      

  2.   

    能详细说以下   offsetTop
                 offsetLeft          offsetParent的用法么?
      

  3.   

    DescriptionReturns the calculated top position of the element in the element's parent coordinates. Syntax
    object.offsetTopResUsing a combination of offset* properties, you can determine the location, width, and height of an element by using the offsetLeft, offsetTop, offsetHeight, and offsetWidth properties. These numeric properties specify the physical coordinates and dimensions of the element relative to the element's offset parent. For example, the following document is a simple clock that adjusts the size of its readout to fit the current width and height of the document body. <HTML>
    <HEAD><TITLE>A Simple Clock</TITLE>
    <SCRIPT LANGUAGE="JScript">
    function startClock() {
        window.setInterval("Clock_Tick()", 1000);
        Clock_Tick();
    }var ratio = 4;
    function Clock_Tick()
    {
        var s = Date();
        var t = s.substring(11,19);
        var doc_height = document.body.offsetHeight;
        var doc_width = document.body.offsetWidth;    if ((doc_height*ratio)>doc_width)
            doc_height = doc_width / ratio;
        document.all.MyTime.innerText = t;
        document.all.MyTime.style.fontSize = doc_height;
    }
    </SCRIPT>
    <BODY onload="startClock()">
    <P ID="MyTime">&nbsp;</P>
    </BODY>
    </HTML>This property has read-only permission. For more information on how to access the dimension and location of elements on the page through the document object model, seeMeasuring Element Dimension and Location.