removeChild(a)是用来删除文档中的已有元素
参数a:要移出的节点
1 <div id="guoDiv"> 2 <span>1</span> 3 <span>2</span> 4 <span>3</span> 5 </div>
1 var oDiv = document.getElementById("guoDiv"); 2 var firsChild = oDiv.firstElementChild ? oDiv.firstElementChild : oDiv.firstChild 3 var returnNode = oDiv.removeChild(firsChild); //移出第一个元素,返回被移出元素 4 alert(returnNode.innerHTML); //1 5 var lastChild = oDiv.lastElementChild ? oDiv.lastElementChild : oDiv.lastChild; 6 returnNode = oDiv.removeChild(lastChild); //移出第后一个元素,返回被移出元素 7 alert(returnNode.innerHTML);//3