轉,insertAdjacentElement方法

來源:互聯網
上載者:User

文法:
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=" 插入 " onclick="rdl_doApply()"></td>
</tr></table>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.