<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
div{
width: 400px;
height: 200px;
margin: 300px auto 50px auto;
border: 1px solid pink;
text-align: center;
line-height: 200px;
font-size: 30px;
color: teal;
}
input{
width: 100px;
height: 40px;
background-color: blue;
color: pink;
border: none;
position: absolute;
top: 550px;
left: 50%;
margin-left: -50px;
}
</style>
</head>
<body>
<div id="div1">注意了啊,抽奖就要开始了</div>
<input type="button" name="btn" id="btn" value="开始" />
<script type="text/javascript">
var oDiv = document.getElementById('div1');
var oBtn = document.getElementById('btn');
var arr=["张三","李四","占全","武力"];
var compare = "true";
var time = null;
oBtn.onclick = function(){
if (compare == true) {
time = setInterval(function(){
var rand = parseInt(Math.random()*(arr.length+1));
oDiv.innerHTML = arr[rand-1];
},100);
oBtn.value = "暂停";
} else{
clearInterval(time);
oBtn.value = "开始";
}
compare = !compare;
}
</script>
</body>
</html>