<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<!--<script src="wws.js" type="text/javascript" charset="utf-8"></script>-->
<style>
div{ width: 200px; height: 100px; background: #ccc;}
</style>
</head>
<body>
<div></div>
<input type="button" value="按钮" id="btn" />
</body>
</html>
<script>
var arr=[];
/*向数组里塞入6个数字*/
function lottery () {
while (arr.length<6) {
var val=rnd(1,34);
if(!findInArr(arr,val)){
arr.push(val);
}
}
arr.sort(function (n,m) {
return n-m;
});
zeroize (arr);
}
var oBtn=document.getElementById('btn');
var oDiv=document.getElementsByTagName('div')[0];
var timer=null;
function change () {
oDiv.innerHTML='';
arr=[];
lottery ();
for (var i=0;i<arr.length;i++) {
oDiv.innerHTML+=arr[i]+' ';
}
}
//初始化
change ();
oBtn.onclick=function () {
clearInterval(timer);
timer=setInterval(function () {
change ();
},50);
setTimeout(function () {
clearInterval(timer);
},600);
}
/*在数组里查找某个值*/
function findInArr(arr,n){
for (var i=0;i<arr.length;i++) {
if(arr[i]==n){
return true;
}
}
return false;
}
/*个位数补零*/
function zeroize (arr) {
for (var i=0;i<arr.length;i++) {
if(parseInt(arr[i])<=9){
arr[i]='0'+arr[i];
}
}
}
/*随机函数*/
function rnd (n,m) {
return parseInt(Math.random()*(m-n)+n);
}
</script>
js彩票效果
最新推荐文章于 2022-05-02 11:20:55 发布