JS實(shí)現(xiàn)設(shè)置ff與ie元素絕對(duì)位置的方法

字號(hào):


    本文實(shí)例講述了JS實(shí)現(xiàn)設(shè)置ff與ie元素絕對(duì)位置的方法。分享給大家供大家參考,具體如下:
    function Show_menu(liid,divid)
    {
      var li=document.getElementById(liid);
      var div=document.getElementById(divid);
      div.style.left=getLeft(li)+140+'px';
      div.style.top= getTop(li)+'px';
      var tt=div.style.top;
      div.style.display='block';
      alert(tt);
    }
    function getTop(e){ //用遞歸方法取值
      var offset=e.offsetTop;
      if(e.offsetParent!=null) offset+=getTop(e.offsetParent);
      return offset;
    }
    function getLeft(e){
      var offset=e.offsetLeft;
      if(e.offsetParent!=null) offset+=getLeft(e.offsetParent);
      return offset;
    }
    希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。