例子:
<div id=mxh>原来的</div>
<input onclick="document.all.mxh.insertAdjacentHTML('beforeBegin','<div>新 加的</div>')" type=button value="Insert Before">
<input onclick="document.all.mxh.insertAdjacentHTML('beforeEnd','<div>新加的 </div>')" type=button value="Insert Before End">
参数有两个,第一个:插入位置;第二个:插入内容;
<div id=mxh>原来的</div>
<input onclick="document.all.mxh.insertAdjacentHTML('beforeBegin','<div>新 加的</div>')" type=button value="Insert Before">
<input onclick="document.all.mxh.insertAdjacentHTML('beforeEnd','<div>新加的 </div>')" type=button value="Insert Before End">
参数有两个,第一个:插入位置;第二个:插入内容;
第一个参数的意义:
[插在这里,值为"beforeBegin"]<div id=test>[插在这里,值为"afterBegin"]
层内<nobr onmousemove="kwM(1);" onmouseout="kwL(event, this);" onmouseover="kwE(event,1, this);" oncontextmenu="return false;" target="_blank" onclick="return kwC();" style="border-bottom: 1px dotted rgb(102, 0, 255); text-decoration: underline; color: rgb(102, 0, 255); background-color: transparent;" id="key1">文字</nobr>
[插在这里,值为"beforeEnd"]</div>[插在这里,值为"afterEnd"]
本文介绍如何使用JavaScript中的insertAdjacentHTML方法来实现HTML元素的插入操作,包括在目标元素的不同位置进行插入。
330

被折叠的 条评论
为什么被折叠?



