var the = event.srcElement ;function getPosition( the )
{
   var x = the.offsetWidth;
   var y = the.offsetTop ;
   var the2 = the ;
   while( the2 && the2.offsetTop && the2.offsetWidth )
   {
       x += the2.offsetWidth ;
       y += the2.offsetTop ;
       the2 = the2.parentNode ;
   }
}

解决方案 »

  1.   

    这是别人给我的源码:如果不是在表格中的话,是正确地,div能够正确地显示在文本字段正下方,但是当文本字段被放在表格中的时候,位置就出问题了,应该如何修改才能够争取的显示呢?
    源代码如下:
    <script language="javascript" type="text/javascript">
    function missde(o){
    t=document.getElementById("menu")
    k=t.style
    k.display=""
    k.pixelTop=o.offsetHeight+o.offsetTop+1
    k.pixelLeft=o.offsetLeft+(o.offsetWidth-t.offsetWidth)/2
    }
    function no(){
    document.getElementById("menu").style.display="none"
    }
    </script>
    <center>
    <input type="text" name="textfield" onMouseOver="missde(this)" onMouseOut="no()">
    <div id="menu" style="border:1px solid #ff0000;width:50px;height:30px;position:absolute;zIndex=100;display:none; background-color:#CCCCCC" >d</div></center>
    这个位置由于表格的问题,而变得不行了,请指点如何修改。
      

  2.   

    看看这样行吗<script language="JavaScript" type="text/JavaScript">
    <!--
    function missde(){
    t=document.getElementById("menu")
    o=document.getElementById("td")
    k=t.style
    k.display=""
    k.pixelTop=o.offsetHeight+o.offsetTop+1
    k.pixelLeft=o.offsetLeft+(o.offsetWidth-t.offsetWidth)/2
    }
    function no(){
    document.getElementById("menu").style.display="none"
    }</script></head>
    <div id="menu" style="border:1px solid #ff0000;width:50px;height:30px;position:absolute;zIndex=100;display:none; background-color:#CCCCCC" >d</div>
    <body>
    <table width="175" height="27" border="0" cellpadding="1" cellspacing="0">
      <tr>
        <td height="25" id="td"><form name="form1" method="post" action="">
          <input type="text" name="textfield" onMouseOver="missde()" onMouseOut="no()">
        </form></td>
      </tr>
    </table>
    </body>
    </html>
      

  3.   

    xishanlang2001(西山狼2000)  的做法是正确的,这是获得一个元素的绝对位置
      

  4.   

    我觉得他的while是不是一个循环?效率是不是低,有没有更简单的方法呢?