javascript案例-----关闭二维码

案例思路:

利用样式的显示和隐藏,display:none隐藏元素 和display:block 显示元素

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			.box{
				position: relative;
				width: 80px;
				height: 80px;
				font-size: 12px;
				text-align: center;
				border: 1px solid #CCCCCC;
				color: #f00;
				margin: 0 auto;
			}
			.box img{
				width: 60px;
				margin-top: 5px;
			}
			.close-btn{
				position: absolute;
				top: -1px;left: -16px;
				width: 14px;
				height: 14px;
				border: 1px solid #CCCCCC;
				line-height: 14px;
				cursor: pointer;
			}
		</style>
	</head>
	<body>
		<div class="box">
			二维码
			<img src="img/erweima.png" >
			<i class="close-btn">X</i>
		</div>
	</body>
	<script type="text/javascript">
		
		//获取样式
		var box=document.querySelector(".box");
		var btn=document.querySelector(".close-btn");
		
		btn.onclick=function(){
			box.style.display="none";
		}
		// 注意:这里不是删掉了,而是隐藏起来了
		
		
	</script>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_45904557/article/details/124833734