<body>
<div>
<button type="button" onclick="add()">添加图片</button>
<button type="button" onclick="del()">删除图片</button>
</div>
<div id='stage'>
</div>
<script type="text/javascript">
var pic;
function add(){
pic = document.createElement("img");
pic.src = "F:\enjoy\doge.png";
var stage = document.getElementById("stage");
stage.appendChild(pic);
}
function del(){
var stage = document.getElementById("stage");
stage.removeChild(pic);
}
</script>
</body>
你题目的解答代码如下:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title> 页面名称 </title>
</head>
<body>
<div>
<button type="button" onclick="add()">添加图片</button>
<button type="button" onclick="del()">删除图片</button>
</div>
<div id='stage'>
</div>
<script type="text/javascript">
var pic;
function add(){
pic = document.createElement("img");
pic.src = "F:\enjoy\doge.png";
var stage = document.getElementById("stage");
stage.appendChild(pic);
}
function del(){
var stage = document.getElementById("stage");
stage.removeChild(stage.lastElementChild);
}
</script>
</body>
</html>
如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!
<body>
<div>
<button type="button" onclick="add()">添加图片</button>
<button type="button" onclick="del()">删除图片</button>
</div>
<div id='stage'>
</div>
<script type="text/javascript">
var pic;
function add(){
pic = document.createElement("img");
pic.src = "F:\enjoy\doge.png";
var stage = document.getElementById("stage");
stage.appendChild(pic);
}
function del(){
var stage = document.getElementById("stage");
stage.remove();
}
</script>
</body>