ボックスは大きくなり、小さくなります

<!DOCTYPE html>
<html>
<head>
<meta charset = "UTF-8">
<title>ボックスが大きくなり、小さくなります</ title>
<style type = "text / css">
.box {
width:50px;高さ:50px;背景:#eee;マージン:0;自動;
}
</スタイル>
</頭>
<body>
<div id = "box" class = "box">

</ div>
<script type = "text / javascript ">
var box = document.getElementById( 'box');
var i = 0; //ユーザーがボックスをクリックした回数を保存します
box.onclick = function(){//ボックスのクリックイベントを処理します
++ i;
if(i%2){//クリック数が奇数で大きくなる
this.style.width = '200px';
this.style.height = '200px';
this.innerHTML = 'Big';
} else {//クリック数はこの数がさらに少なくなる
this.style.width = '50px';
this.style.height = '50px';
this.innerHTML = '小';
}
}
</ script>
</ body>
</ html>

おすすめ

転載: www.cnblogs.com/jiaqi818/p/12730981.html