JavaScript中删除子节点的方法有以下几种:
var parent = document.getElementById("parent");
var child = document.getElementById("child");
parent.removeChild(child);
var child = document.getElementById("child");
child.remove();
var parent = document.getElementById("parent");
parent.innerHTML = "";
var parent = document.getElementById("parent");
while (parent.firstChild) {
parent.removeChild(parent.firstChild);
}
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: JavaScript怎样验证表单输入的有效性