日期:2014-05-16  浏览次数:20363 次

分享一下JS写的抽奖功能-可以用于现场、公司内部活动的抽奖
JS写的抽奖功能
很简单的JS程序,没有做配置功能
可以用于现场、公司内部活动的抽奖
代码运行效果:http://www.99rfid.com/cj.htm

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>js-test</title>
</head>
<style type=text/css>
.DonforAll{Float:Left;Width:333px;}
.DonforAll .DonforKj{Float:left;Width:110px;height:60px;Padding-Top:30px;Margin:1px auto auto 1px;BackGround:#D6F271;color:#156A00;Font-Weight:600;text-align:center;}
.DonforXs{Float:Left;Width:100%;Font-Weight:600;Font-Size:14px;Height:auto;Clear:both;Color:#ff0000;Padding:0 0 20px 0;}
.Donfor{Float:Left;Width:100%;}
</style>
<script language=javascript>
<!---
var all=8;
var aa;
//document.getElementById("d0").innerHTML="<input type=button value='抽奖'  onclick='doexe()'>";
//document.getElementById("d0").innerHTML +=" <input type=button value='停止'  onclick='doexit()'>";
function doexe(){
 var a=parseInt(Math.random() * 8)+1;
 var t=parseInt(Math.random() * 30)+80;
 var d=1;
 document.getElementById("cjan").style.display="none";
 document.getElementById("listjp").innerHTML="<br><br><span style='color:#ff0000;'>抽奖中,请等待····<br><br></span>";
 document.getElementById("aa").value=a;
 document.getElementById("dd").value=d;
 document.getElementById("tt").value=t;
 aa=setTimeout("turn()",200);
}
function reexe(){
 var a=parseInt(Math.random() * 8)+1;
 var t=parseInt(Math.random() * 30)+80;
 var d=1;
 document.getElementById("cjan").style.display="none";
 document.getElementById("aa").value=a;
 document.getElementById("dd").value=d;
 document.getElementById("tt").value=t;
 for(var i=1;i<=all;i++){
    //document.getElementById("d"+i).innerHTML="";
    document.getElementById("d"+i).style.backgroundColor="#D6F271";
    document.getElementById("d"+i).style.color="#ffffff";
 }
 aa=setTimeout("turn()",200);
}
//a 中奖号
//c 转数
//t 统计数
//d 转的当前号
function turn(){
 var a=parseInt(document.getElementById("aa").value);
 var d=parseInt(document.getElementById("dd").value);
 var t=parseInt(document.getElementById("tt").value);
 if(t==1){
  for(var i=1;i<=all;i++){
   if(i==a){
    //document.getElementById("d"+i).innerHTML="<b>中奖了<br>哈哈</b>";
    document.getElementById("d"+i).style.backgroundColor="951700";
    document.getElementById("d"+i).style.color="#ffffff";
    document.getElementById("listjp").innerHTML="<br><br><span style='color:#ff0000;'>恭喜您,您所中的奖品是:"+document.getElementById("d"+i).innerHTML +"<br><br></span>";
   }else{
    //document.getElementById("d"+i).innerHTML="";
    document.getElementById("d"+i).style.backgroundColor="#D6F271";
    document.getElementById("d"+i).style.color="#156A00";
   }
   document.getElementById("d0").innerHTML="<input type=button value='重来' id=cjan  onclick='reexe()'><input type=button&nbs