代码如下:
1.HTML部分:
<div>
<img src="advertising.png" title="广告">
<a href="#">×</a>
</div>
2.CSS部分:
<style>
div {
position: relative;
}
img {
width: 100%;
height: 200px;
}
div a {
text-decoration: none;
position: absolute;
top: 10px;
right: 10px;
background-color: rgba(0, 0, 0, 0.2);
width: 20px;
height: 20px;
text-align: center;
line-height: 20px;
color: white;
}
</style>
3.JS部分:
<script>
var cross = document.querySelector('a');
var img = document.querySelector('img');
cross.onclick = function() {
img.style.display = 'none';
this.style.display = 'none';
}
</script>