2017-05-30 14:11:11
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<button id="btn1">开始</button>
<button id="btn2">结束</button>
<h1 id="con"></h1>
<script type="text/javascript">
var arr=["袁杰","李鑫辉","孙萌","宋道孟",
"程玉鹏","李峰","李荣民","王县萍","张洪","张恒利",
"张富旺","冯锦强","赵玉玲","尚戈","张枭阳","武婷",
"孙闯","陈笑天","王小虎","王志豪","郭一凯","弓的矢",
"何守波","梁正峰","王劲根","武淑婷","李增辉","王智辉",
"王世瑶","郑宇泽","胡银广","李浩辰","马硕明","刘帅",
"赵永泽","张琦","姚瑶","秦志梁","景琴琴","谢家兴","冯小威"]
//随机封装函数
function ran(min,max){
return parseInt(Math.random()*(max-min+1)+min)
}
//点击开始
var a;//声明一个变量a
btn1.onclick=function(){
clearInterval(a)//在启动计时器时清除前面的计时器;
a=setInterval(function(){
con.innerHTML=arr[ran(0,arr.length-1)];
con.style.color="rgb("+ran(0,255)+","+ran(0,255)+","+ran(0,255)+")"//字体随机变色
},1)
}//把计时器赋值给变量a
//点击结束
btn2.onclick=function(){
clearInterval(a)//清除计时器
}
</script>
</body>
</html>
网友评论