<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">
		.out{
			width: 500px;
			height: 500px;
			background-color: Coral;
		}
		.middle{
			width: 300px;
			height: 300px;
			background-color: Wheat;
			margin:auto;
			transform: translateY(calc(250px - 150px));
		}
		.inside{
			width: 100px;
			height: 100px;
			background-color: PaleGoldenRod;
			margin: auto;
			transform: translateY(calc(150px - 50px));
		}
	</style>
</head>
<body>
	<div class="out">
		<div class="middle">
			<div class="inside"></div>
		</div>
	</div>
	<script type="text/javascript">
		var i =0;
		document.getElementsByClassName('inside')[0].onclick=function(){
			i++;
			this.appendChild(document.createTextNode('按到我了'+i));
		}
		document.getElementsByClassName('middle')[0].onclick=function(){
			i++;
			this.appendChild(document.createTextNode('按到我了'+i));
		}
		document.getElementsByClassName('out')[0].onclick=function(){
			i++;
			this.appendChild(document.createTextNode('按到我了'+i));
		}
		/*註:這裡如果把this換成e.target就沒有這個效果*/
	</script>
</body>
</html>

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Jerry 的頭像
    Jerry

    Bug倉庫 // 程式日記

    Jerry 發表在 痞客邦 留言(0) 人氣()