object.insertAdjacentElement(sWhere, oElement)在一个制定的位置插入一个元素

来源:互联网 发布:mac系统清理工具 编辑:程序博客网 时间:2024/05/01 06:38

在一个临近的指定的位置插入一个元素.

语法:

oElement = object.insertAdjacentElement(sWhere, oElement)
 参数:

sWhere  必需. 指出插入的位置, 用下名的值:
beforeBegin 在目标元素的外部开头位置. <i><o>..</o>
afterBegin  在目标元素的内部开头位置. <o><i>..</o>
beforeEnd  在目标元素的内部结束位置. <o>..<i></o>
afterEnd  在目标元素的外部结束位置. <o>..</o><i> 
 
oElement 必需. 要插入的元素du.

Return Value

返回插入的元素对象.

备注

You cannot insert text while the document is loading. Wait for the onload event before attempting to call this method.
当document加载的时候,你不可以插入一个文本。在尝试调用这个方法之前,会等待载入事件结束。

If you try to insert an object that already exists on the page, the existing object will be moved to the point that you specified in the insertAdjacentElement method; no new object will be created.
如果你试图插入一个存在的对象,那么现存的对象将要移动到你指定的地方,不再重新创建一个对象。

Example
例子

This example uses the insertAdjacentElement method to add a new list item to an ol object.

HideExample

<SCRIPT>
function fnAdd()
{
var oNewItem = document.createElement("LI");
oList.children(0).insertAdjacentElement("BeforeBegin",oNewItem);
oNewItem.innerText = "List Item 0";
}
</SCRIPT>
:
<BODY>
<OL ID = "oList">
<LI>List Item 1</LI>
<LI>List Item 2</LI>
<LI>List Item 3</LI>
</OL>
<INPUT TYPE = "button" VALUE = "Add Item" onclick="fnAdd()">
</BODY>

原创粉丝点击