点击有惊喜
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
*{
padding: 0;
margin: 0;
}
#surprised{
width: 400px;
height: 200px;
font-size: 30px;
text-align: center;
line-height: 200px;
margin: 20px auto;
color: white;
background-color: blue;
}
</style>
</head>
<body>
<div id="surprised">点击有惊喜
</div>
</body>
<script type="text/javascript">
var oDiv=document.getElementById('surprised');
var clickTimer=0;
oDiv.onclick=function(){
switch(clickTimer%4){
case 1:
this.style.backgroundColor='green';
this.innerText='再次点击试试';
break;
case 2:
this.style.backgroundColor='pink';
this.innerText='看来你点错啦';
break;
case 3:
this.style.backgroundColor='red';
this.innerText='再点开看看';
break;
default:
this.style.backgroundColor='blue';
this.innerText='点击有惊喜';
}
clickTimer++;
}
</script>
</html>