//设置某一个控件与另一个控件的相对位置 function SetPostion() { var oLstZdwz = document.getElementById("<%=控件名称.ClientID %>"); var oTxtZdwzCx = document.getElementById("<%=控件名称.ClientID %>"); var xy = this.getAbsPoint(oTxtZdwzCx); oLstZdwz.style.left = xy.x + "px"; oLstZdwz.style.top = (xy.y + oTxtZdwzCx.offsetHeight) + "px"; //oLstZdwz.style.visibility = "hidden"; //visibility:hidden; //设置下级机构的位置 var oTxtXjjgcx = document.getElementById("<%=控件名称.ClientID %>"); var oLstXjjg = document.getElementById("<%=控件名称.ClientID%>"); var xyjg = getAbsPoint(oTxtXjjgcx); oLstXjjg.style.left = xyjg.x + "px"; oLstXjjg.style.top = (xyjg.y + oTxtXjjgcx.offsetHeight) + "px"; //oLstXjjg.style.visbility = "hidden"; } //获取控件在页面中的位置 //2013/5/5 shzhang function getAbsPoint(e) { var x = e.offsetLeft; var y = e.offsetTop; while (e = e.offsetParent) { x += e.offsetLeft; y += e.offsetTop; } return { "x": x, "y": y }; }
设置两个控件的相对位置