关于offsetParent,求助!

csdnggn0113 2003-09-29 12:03:21
js中,offsetParent是什么,怎么用,谢谢!!!!!!!!
...全文
37 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
honker110 2003-09-29
  • 打赏
  • 举报
回复
this.offsetParent返回包含这个元素的元素,offsetTop和offsetLeft就是相对于offsetParent定义的,看看下面的代码你就明白了:
<HTML>
<HEAD>
<TITLE>Elements: Positions</TITLE>
<SCRIPT LANGUAGE="JScript">

function showPosition()
{
var oElement = document.all.oCell;

alert("The TD element is at (" + oElement.offsetLeft +
"," + oElement.offsetTop + ")\n" + "The offset parent is "
+ oElement.offsetParent.tagName );
}
</SCRIPT>
</HEAD>
<BODY onload="showPosition()">
<P>This document contains a right-aligned table.
<TABLE BORDER=3 ALIGN=right>
<TR>
<TD ID=oCell>This is a small table.</TD>
</TR>
</TABLE>
</BODY>
</HTML>
你可以把table 的border设得大点或小点试试
kingdomzhf 2003-09-29
  • 打赏
  • 举报
回复
offsetParent --Retrieves a reference to the container object that defines the offsetTop and offsetLeft properties of the object.

有一些具体的细节:
1.for ie5.0 and above,the offsetParent property return the table object for the td object in ie4.0 it returns the tr object
2.大多数情况下offsetParent得到的是body.div ,span具有容器这种特性
3.offsetParent与position有很大的关系

87,901

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧