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)+")"http://字體隨機變色
},1)
}//把計時器賦值給變量a
//點擊結束
btn2.onclick=function(){
clearInterval(a)//清除計時器
}
</script>
</body>
</html>