<案例演示>
<!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>Document</title>
<style>
.box{
width: 74px;
height: 88px;
margin: 100px auto;
border: 1px solid orange;
position: relative;
}
img{
width: 60px;
margin-top: 5px;
}
.close-btn{
position: absolute;
top: -1px;
right: -1px;
width: 14px;
height: 14px;
border: 1px solid orange;
line-height: 14px;
cursor: pointer; /*经过x的时候鼠标图标变成小手 */
}
</style>
</head>
<body>
<div class="box">
<img src="https://img.alicdn.com/tps/i3/T1OjaVFl4dXXa.JOZB-114-114.png" >
<span class="close-btn">x</span>
</div>
<script>
// 1.获取元素
var btn = document.querySelector('.close-btn');
var box = document.querySelector('.box');
// 2.注册事件 3.处理程序
btn.onclick=function(){
box.style.display = 'none';//点击按钮 盒子的样式变为隐藏
// display none 隐藏 ; block 显示
}
</script>
</body>
</html>