insertAdjacentElement方法使用

insertAdjacentElement方法使用

分類: JavaScript Ajax 1713人閱讀 評論(0) 收藏 舉報

語法:
oElement = object . insertAdjacentElement ( sWhere , oElement )
參數:
oElement :  必選項。對象(Element)。要插入到 object 鄰近的對象。

sWhere :  必選項。字符串(String)。beforeBegin | afterBegin | beforeEnd | afterEnd beforeBegin :  將 oElement 插到 object 的開始標籤之前。
afterBegin :  將 oElement 插到 object 的開始標籤之後。但是在 object 的所有原有內容之前。
beforeEnd :  將 oElement 插到 object 的結束標籤之前。但是在 object 的所有原有內容之後。
afterEnd :  將 oElement 插到 object 的結束標籤之後。


返回值:
oElement :  對象(Element)。返回插入的對象的引用。

說明:
將 oElement 依據 object 定位插入文檔結構。
當文檔正在載入時,不可以嘗試此方法。必須在 onload 事件觸發以後。
假如你嘗試插入一個已經在文檔結構中存在定位的對象,該對象將被移動到你指定的插入位置,而不會有新對象被創建。

<script>
var i_nowheight=250;
function rdl_doApply(e){
with (document.all("oSelect1")) var sParam1=options[selectedIndex].value;
with (document.all("oSelect2")) var sParam2=options[selectedIndex].value;
var oNewNode=document.createElement(sParam1);
oList.insertAdjacentElement(sParam2,oNewNode);
oNewNode.innerText=sParam2
i_nowheight+=30;
window.resizeTo(360,i_nowheight);
}
</script>


<div id=oCode>
<ul id=oList>
<li>列表項目1
<li>列表項目2
</ul>
</div>
<table height=56><tr>
<td><select style="width:100px;" id=oSelect1>
<option value="button" selected>button</option>
<option value="b">b</option>
</select></td>
<td><select style="width:100px;" id=oSelect2>
<option value="beforeBegin" selected>beforeBegin</option>
<option value="afterBegin">afterBegin</option>
<option value="beforeEnd">beforeEnd</option>
<option value="afterEnd">afterEnd</option>
</select></td>
<td><input type=button value=" 插入 " οnclick="rdl_doApply()"></td>
</tr></table>


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