js中怎么刪除由createElement添加的多個(gè)重復(fù)的元素標(biāo)簽?問(wèn)題描述:點(diǎn)擊“添加”按鈕,就會(huì)在網(wǎng)頁(yè)上添加一個(gè)"HelloWorld"的p標(biāo)簽,點(diǎn)一次會(huì)添加一個(gè);然后點(diǎn)擊“刪除”按鈕,那么就會(huì)刪除一個(gè)p標(biāo)簽,而剩下的不會(huì)刪除。那么怎么刪除剩下的標(biāo)簽?zāi)兀縃TML代碼:<button onclick="add()">添加</button><button onclick="del()">刪除</button>JS代碼:function add(){
ina = document.createElement("p");
ina.innerHTML = "HelloWorld";
ina.style.color = "red";
ina.style.fontSize = "20px"; document.body.appendChild(ina);
}function del(){ var parent = ina.parentNode;
parent.removeChild(ina);
}
js中怎么刪除由createElement添加的多個(gè)重復(fù)的元素標(biāo)簽?
不負(fù)相思意
2018-10-16 17:27:01