完整版点名器

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title></title>

<style type="text/css">

#wrap{

width: 680px;

margin: 200px auto 30px auto;

border: 1px solid gray;

text-align: center;

background-color: white;

}

#wrap div{

width: 100px;

height: 60px;

background-color: greenyellow;

border-radius: 10px;

display: inline-block;

text-align: center;

line-height: 60px;

margin: 10px;

}

input{

width: 100px;

height: 40px;

text-align: center;

line-height: 40px;

background-color: pink;

border: none;

border-radius: 10px;

font-size: 18px;

margin-left: 46%;

}

</style>

</head>

<body>

<div id="wrap">

<div>11</div>

<div>22</div>

<div>33</div>

<div>44</div>

<div>55</div>

<div>66</div>

<div>77</div>

<div>88</div>

<div>99</div>

<div>00</div>

</div>

<input type="button" name="btn" id="btn" value="开始" />

<script type="text/javascript">

var allDiv = document.getElementsByTagName('div');

var oBtn = document.getElementById('btn');

var time = null;

var compare = true;

oBtn.onclick = function(){

if (compare == true) {

time = setInterval(function(){

//得到一个随机数

var rand = parseInt(Math.random()*(allDiv.length-1)+1);

allDiv[rand].style.backgroundColor = "red";

allDiv[0].style.backgroundColor = "";

for (var i=1;i<allDiv.length;i++) {

//如果不相等则恢复原来的颜色

if (i != rand) {

allDiv[i].style.backgroundColor = "";

}

}

},30);

oBtn.value = "暂停";

} else{

clearInterval(time);

oBtn.value = "开始";

}

compare = !compare;

}

</script>

</body>

</html>



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值