<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id = 'box'>请开始抽奖</div><br>
<button id = 'star'>开始</button><button id = 'end'>结束</button>
<input type="text" id = 'text'>
<script type="text/javascript">
var arr = ['小李','小王','小刘','小黑','小白'];
function math (min,max){
return parseInt(Math.random()*(max-min+1));
};
function $(id){
return document.getElementById(id);
};
var timer
$('star').onclick = function () {
clearInterval(timer);
timer = setInterval(function(){
$('box').innerHTML = arr[math(0,arr.length-1)];
$('text').value = $('box').innerHTML;
},30)
};
$('end').onclick = function () {
clearInterval(timer);
}
</script>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id = 'box'>请开始抽奖</div><br>
<button id = 'star'>开始</button><button id = 'end'>结束</button>
<input type="text" id = 'text'>
<script type="text/javascript">
var arr = ['小李','小王','小刘','小黑','小白'];
function math (min,max){
return parseInt(Math.random()*(max-min+1));
};
function $(id){
return document.getElementById(id);
};
var timer
$('star').onclick = function () {
clearInterval(timer);
timer = setInterval(function(){
$('box').innerHTML = arr[math(0,arr.length-1)];
$('text').value = $('box').innerHTML;
},30)
};
$('end').onclick = function () {
clearInterval(timer);
}
</script>
</body>
</html>