广告栏点击消失事件

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>点击事件消失</title>
<style>
*{
padding: 0px;
margin: 0px;
}
.topbanner{
background-color: blue;
height: 80px;


}
.w{
width: 1210px;

margin: 0px auto;
position: relative;
}
img{
width: 1210px;
height: 80px;

}
a{
text-decoration: none;
color:#FFF;
position: absolute;
background: black;
top: 5px;
right: 5px;
width: 20px;
height: 20px;
text-align: center;

}
.hide{
display: none!important;
}
</style>
</head>
<body>
<div class="topbanner" >

<div class="w" id="box">
<img src="img/0.jpg" alt="guanggaolan">
<a href="#" id="closebanner" >X</a>
</div>

</div>
<script type="text/javascript">
var closebanner=document.getElementById("closebanner");
var topbanner=document.getElementById("box");

closebanner.onclick=function(){
topbanner.className="hide";
}

</script>
</body>
</html>

引用topbanner.className,通过找类名来实现

猜你喜欢

转载自www.cnblogs.com/qinxuhui/p/9560818.html