无语了,这个js的代码也写错了吗?我怎么感觉没错啊,但是就是删除不了也替换不了,求解详解必采纳
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>删除和修改节点</title>
</head>
<body>
<ul>
<li>
<img src="./image/冬裙.webp" id="first">
<p><input type="button" value="删除我吧" onclick="del()"></p>
</li>
<li>
<img src="./image/雪地靴.webp" id="second">
<p><input type="button" value="替换我吧" onclick="rep()"></p>
</li>
</ul>
<script>
function del(){
var delNode=document.getElementById("first");
delNode.parentNode.removeChild(delNode);
}
function rep(){
var oldNode=document.getElementById("second");
//创建新的图片
new newNode=document.createElement("img");
newNode.setAttribute("src","./image/毛衣.jpg");
oldNode.parentNode.replaceChild(newNode,oldNode);
}
</script>
</body>
</html>