點擊關閉廣告

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			.box {
				position: relative;
				width: 74px;
				height: 88px;
				border: 1px solid #ccc;
				margin: 100px auto;
				text-align: center;
				font-size: 12px;
				color: #f40;
			}
			
			.box img {
				width: 60px;
				margin-top: 5px;
			}
			.close-btn {
				position: absolute;
				top: -1px;
				left: -16px;
				width: 14px;
				border: 1px solid #CCC;
				line-height: 14px;
				font-family: arial, helvetica, sans-serif;
				cursor: pointer; 
				color: #CCCCCC;
			}
		</style>
	</head>
	<body>
		<div class="box">
			廣告
			<img src="../apiimg/廣告.png" alt="">
			<i class="close-btn">x</i>
		</div>
		<script type="text/javascript">
			//獲取元素
			var btn = document.querySelector('.close-btn');
			var box = document.querySelector('.box');
			//註冊事件 程序處理
			btn.onclick = function() {
				box.style.display = 'none';   //隱藏div
			}
		</script>
		
	</body>
</html>



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章