offsetParent Property--------------------------------------------------------------------------------Retrieves a reference to the container object that defines the offsetTop and offsetLeft properties of the object.SyntaxHTML N/A
Scripting [ oElement = ] object.offsetParent Possible ValuesoElement Object that receives the container object. The property is read-only. The property has no default value.Expressions can be used in place of the preceding value(s), as of Microsoft?Internet Explorer 5. For more information, see Dynamic Properties.ResMost of the time the offsetParent property returns the body object.Note In Microsoft?Internet Explorer 5, the offsetParent property returns the TABLE object for the TD object; in Microsoft?Internet Explorer 4.0 it returns the TR object. You can use the parentElement property to retrieve the immediate container of the table cell.
ExampleThis example shows how to determine the position of a TD object. Although the TD object appears to the far right in the document, its position is close to the x-axis and y-axis, because its offset parent is a TABLE object rather than the document body. For Internet Explorer 4.0, this same example returns a position of 0,0 because the offset parent is the table row.<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=1 ALIGN=right>
<TR>
<TD ID=oCell>This is a small table.</TD>
</TR>
</TABLE>
</BODY>
</HTML>
Scripting [ oElement = ] object.offsetParent Possible ValuesoElement Object that receives the container object. The property is read-only. The property has no default value.Expressions can be used in place of the preceding value(s), as of Microsoft?Internet Explorer 5. For more information, see Dynamic Properties.ResMost of the time the offsetParent property returns the body object.Note In Microsoft?Internet Explorer 5, the offsetParent property returns the TABLE object for the TD object; in Microsoft?Internet Explorer 4.0 it returns the TR object. You can use the parentElement property to retrieve the immediate container of the table cell.
ExampleThis example shows how to determine the position of a TD object. Although the TD object appears to the far right in the document, its position is close to the x-axis and y-axis, because its offset parent is a TABLE object rather than the document body. For Internet Explorer 4.0, this same example returns a position of 0,0 because the offset parent is the table row.<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=1 ALIGN=right>
<TR>
<TD ID=oCell>This is a small table.</TD>
</TR>
</TABLE>
</BODY>
</HTML>
解决方案 »
- 用JS调用OCX,能收到事件,但事件传递的参数为什么是undefined
- 鼠标移动型不能保持
- 问一个关于可编辑 listbox 的问题!在线等
- 字符串分割问题,求助!
- jquery 录入部分中文或英文代码 同是把中文和英文中时显示在两个输入框内
- 提取标题title内容
- javascript中confirm()返回值
- 在静态页如a.html 里,里面有一个表格,能不能每单激一个按钮,表格就会加一行,也可以类似效果的
- 后台执行完成后再执行前台,该如何解决?
- 一段jquery正则表达式取出一段指定的html内容
- 对table的控制,有个问题想请教
- ########利用object嵌入htm文件的问题$$$$$$$$$$$$
Scripting [ oElement = ] object.parentElement Possible ValuesoElement Object that receives the parent. The property is read-only. The property has no default value.Expressions can be used in place of the preceding value(s), as of Microsoft?Internet Explorer 5. For more information, see Dynamic Properties.ResThe topmost object returns null as its parent.
div如果不设置position属性,就不会对下层的元素的位置产生影响,事实也是这样。不设position的div仅仅是一个块流元素
<table border="1">
<tr id="t"><td>12321312</td></tr>
</table>
<div style="border: 1px solid black;position:absolute;">
<form>
<input type="checkbox" id="cc">
</form>
</div><SCRIPT LANGUAGE="JavaScript">
alert(t.parentElement.tagName)
alert(t.offsetParent.tagName)alert(document.all.cc.parentElement.tagName)
alert(document.all.cc.offsetParent.tagName)
</SCRIPT>