点击开始抽奖,然后设定人员开始不定的改变,直到点击停止为止
代码如下
<div class="div">
<h2>Who?</h2>
<img src="cankao/start.jpg" width="100" id="q"> <img src="cankao/end.jpg" width="100" id="p">
</div>
</body>
<script>
var usernames=["张三","李四","王五","赵六","孙琦","钱吧","八六"];
var b=0;
var c=0;
function chou() {
var a=document.querySelector("h2");
c=setInterval(function () {
if(b>usernames.length-1){
b=0;
}
a.innerHTML = usernames[b];
b++;
},100);
}
function ding() {
clearInterval(c);
}
document.querySelector("#q").onclick=chou;
document.querySelector("#p").onclick=ding;
</script>