<!DOCTYPE html>
<html>
<head>
<title>添加、删除</title>
<meta charset="utf-8" />
<style type="text/css">
html,body{
background-color:#ffffff;
width:100%;
height:100%;
overflow:hidden;
}
#stage{
margin:10px;
width:600px;
height:500px;
}
</style>
<body>
<div>
<button type="button" onclick="add()">添加图片</button>
<button type="button" onclick="del()">删除图片</button>
</div>
<div id='stage'>
</div>
<script type="text/javascript">
function add(){
//补全添加图片代码
var a = document.createElement("img");
a.src = "res/plane_blue_01.png";
a.className = "plane";
document.getElementById("stage").appendChild(a);
}
function del(){
//补全删除图片代码
//name里存储了所有的飞机图片,每次点击调用一次del函数name里的飞机图片先是刷新一下存储图片,后在删除
var name = document.getElementsByClassName("plane");
document.getElementById("stage").removeChild(name[0]);
}
</script>
</body>
</html>
点击添加图片,添加一个飞机图片;点击删除图片,删除页面上的一个飞机图片