方法
//判断是否有节点hasChildNodes() 得到的是布尔值*
console.log(nlist.hasChildNodes())*//true*
console.log(li.hasChildNodes())*//true 文本也是*
创建节点
document.create Element(节点名称)
var newLi=document.createElement('li')
向当前节点末尾添加子节点
appendChild(),父元素.appendChild(新节点)
*// nlist.appendChild(newLi)*
btn.onclick = function () {
*//创建li标签*
var newLi = document.createElement('li')
newLi.innerHTML=Math.round( Math.random()*10)
*//添加标签*
nlist.appendChild(newLi)
}
向指定位置添加
insertBefore(新节点,参照节点)
add.onclick=function(){
*//1创建标签*
var newLi = document.createElement('li')
*//吩咐内容*
newLi.innerHTML=Math.round( Math.random()*100)
*//添加*
nlist.insertBefore(newLi,li)*//新节点,旧节点猪,在猪之前加入*
}
替换
父元素.replaceChild(新节点,替换节点)
var newL=document.createElement('li')
newL.innerHTML='烤猪'
nlist.replaceChild(newL,ya)
删除
父元素.removeChild(子节点)
nlist.removeChild(li)//猪没了
克隆
cloneNode(布尔值) true克隆子节点(文本内容),false不克隆子节点
var newthree=li.cloneNode(true)//不写默认false
nlist.appendChild(newthree)