insertAdjacentText方法与 insertAdjacentHTML方法相似,只不过只能插入纯文本,参数相同
insertAdjacentHTML 方法:在指定的地方插入html标签语句
原型:insertAdajcentHTML(swhere,stext)javascript
参数:
swhere: 指定插入html标签语句的地方,
stext:要插入的内容html
有四种参数可用:java
beforeBegin: 插入到标签开始前app
afterBegin: 插入到标签开始标记以后code
beforeEnd: 插入到标签结束标记前htm
afterEnd: 插入到标签结束标记后ip
oBtn.onclick=function(){ var oLi=document.createElement('li'); var oInp=document.createElement('input'); var oA=document.createElement('a'); oA.href='javascript:;'; oA.innerHTML='删除'; oInp.type='checkbox'; oLi.innerHTML=oText.value;//先把标签里的文字经过innerHTML方式写好 oLi.insertAdjacentElement('afterBegin',oInp);//接着能够在内容前加上单选框 oLi.insertAdjacentElement('beforeEnd',oA);//在内容后加上a标签,a标签里也能够有内容 oUl.appendChild(oLi); };