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

在一個臨近的指定的位置插入一個元素.

語法:

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" οnclick="fnAdd()">
</BODY>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章