题解 | #点击按钮隐藏元素#
点击按钮隐藏元素
http://www.nowcoder.com/practice/9b0016737b3040aaa61316890f1ac3f8
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
</head>
<body>
<div class='box'>
<div class='btn'>X</div>
</div>
</body>
</html>
.box {
width: 100px;
height: 100px;
border: solid 1px black;
position: relative;
}
.btn{
width: 20px;
height: 20px;
background-color: red;
position: absolute;
right: 0;
top: 0;
text-align: center;
line-height: 20px;
}
var btn = document.querySelector('.btn');
var box = document.querySelector('.box');
btn.onclick = function(){
// 补全代码
box.style.display = "none"
}