close
<!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>
全站熱搜