时间:2021-07-01 10:21:17 帮助过:30人阅读
<div id="guoDiv">
<span>1</span>
<span>2</span>
<span>3</span>
</div>
var oDiv = document.getElementById("guoDiv");
var deepList = oDiv.cloneNode(true); //拷贝子节点
alert(deepList.childNodes.length); //3或7(兼容性问题,所以结果不一样)
var showList = oDiv.cloneNode(false); //只拷贝当前元素的引用
alert(showList.childNodes.length); //0