<input type="button" id="startButton" name="Button" value="开始" style="POSITION: absolute;">
<script>
function getDim(el){
var rd = {x:0,y:0}
do{
rd.x += el.offsetLeft
rd.y += el.offsetTop
el = el.offsetParent
} while(el)
return rd
}</script><span id=MySpan>获得非定位元素的坐标值</span><script>
mySpanDim = getDim(document.all.startButton)
alert("startButton : x:" + mySpanDim.x + ", y:" + mySpanDim.y)
</script>
<script>
function getDim(el){
var rd = {x:0,y:0}
do{
rd.x += el.offsetLeft
rd.y += el.offsetTop
el = el.offsetParent
} while(el)
return rd
}</script><span id=MySpan>获得非定位元素的坐标值</span><script>
mySpanDim = getDim(document.all.startButton)
alert("startButton : x:" + mySpanDim.x + ", y:" + mySpanDim.y)
</script>
解决方案 »
- window.open的问题
- 还是JS获取当前URL的问题
- 一个很精致(个人是这么认为的,尽管没有界面)的JavaScript贪吃蛇游戏
- 关于js连接目标网站是否响应的问题
- 怎么样实现点左边的treeView页面显示在右边,和csdn的社区这样
- 求eclipse的js Formatter模板
- 如何根据前一组单选决定下一组单选中的部分选项不能被选择?
- 请问一下网页变化时加载的效果
- 关于三角函数的问题 一个三百年前已忘得一干二净的问题
- 用Input+Div实现类似Select的效果,定位问题,请教如何处理
- 如何用javascript读取源文件!在线等!!!!!!!急
- 请教:我想锁定弹出窗口,即必须先响应子窗口,子窗口关闭后才能够响应父窗口,javascript可以控制么?如何控制?
This property reflects the value of the Cascading Style Sheets (CSS) left attribute for positioned items. This property always returns zero for nonpositioned items because "left" has meaning only when the object is positioned. If the left attribute is not set, the posLeft property returns zero. Use the offsetLeft property to calculate actual positions within the document area.Setting this property changes the value of the left position but leaves the units designator for the property unchanged.Unlike the left property, the posLeft property value is a floating-point number, not a string.For more information about how to access the dimension and location of elements on the page through the Dynamic HTML (DHTML) Document Object Model (DOM), see Measuring Element Dimension and Location.
<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>//VBScript
<script language="VBScript"><!--
function getIE()
dim t,l,a,b
set a=document.all.img1
t=document.all.img1.offsetTop
l=document.all.img1.offsetLeft
while a.tagName<>"BODY"
set a = a.offsetParent
t=t+a.offsetTop
l=l+a.offsetLeft
wend
msgbox "top="&t&chr(13)&"left="&l,64,"得到控件的位置"
end function
--></script>