控件没有设置style的情况下,获取它的位置x,y this.getBoundingClientRect().topthis.getBoundingClientRect().left左上角坐标是0,0 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不要用style,用currentStyle下面是得到对象的绝对位置<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> //使用方法var tempobj = document.getElementById("控件ID");var pos = getAbsolutePosition(tempobj);alert(""+pos.x+","+pos.y);//函数function getAbsolutePosition(obj){ position = new Object(); position.x = 0; position.y = 0; var tempobj = obj; while(tempobj!=null && tempobj!=document.body) { position.x += tempobj.offsetLeft + tempobj.clientLeft; position.y += tempobj.offsetTop + tempobj.clientTop; tempobj = tempobj.offsetParent } return position;} document.body.scrollTop+document.documentElement.scrollTop+tempobj.offsetTop + tempobj.clientTop 求正则表达式 如何让图片在网页上轮循显示 请问:这个是什么意思data = data || [] 为什么返回的是1,(function(x){ delete x; return x; })(1); 有關正則表達式的問題 怎么计算每个月的第一天是星期几? JAVASCRIPT怎么设置服务器控件的属性?在线等高人解答! 取jsp页面内容 关闭窗口问题!急.... 怎么樣屏蔽最大化? ------给textbox换行,咋整? ________-----javascript的問題
下面是得到对象的绝对位置
<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>
var tempobj = document.getElementById("控件ID");
var pos = getAbsolutePosition(tempobj);
alert(""+pos.x+","+pos.y);//函数
function getAbsolutePosition(obj)
{
position = new Object();
position.x = 0;
position.y = 0;
var tempobj = obj;
while(tempobj!=null && tempobj!=document.body)
{
position.x += tempobj.offsetLeft + tempobj.clientLeft;
position.y += tempobj.offsetTop + tempobj.clientTop;
tempobj = tempobj.offsetParent
}
return position;
}