<html>

<head>

<title>

抽奖

</title>

<script language="javascript" type="text/javascript">

/*

1、要有随机数

2、创建一个数组

3、点击按钮控制

4、先抽一等奖,再抽二等奖,最后是三等奖

5、一点击停止就会把 名字从数组中删除掉,并且把名字放到该放的框中

6、先定义一个空变量,每点击一次开始就让这个变量累加一

7、取6中的变量,判断变量数值的范围,当是一时,就将第一次出现的名字放到一等奖的框中并且将给名字从数组中去除掉

第二次和第三次出现的名字放到二等奖中并且将给名字从数组中去除掉,第四五六次的名字放到三等奖的框中并且将给名字从数组中去除掉


*/

//先定义一个随指定时间执行指定函数的变量

var t="";

//定义一个抽奖次数变量

var numbers=0;

//定义一个被抽到人名变量

var m="";

//定义一个随机数变量

var  num="";

//定义一个累加变量

var j=1;

//定义一个人名数组,数组中的元素就是自己想要抽取的人名,自己也可以增加,更改人名

var str=new Array("张三","李四","赵武","王六","王二","麻子","王琦","刘冰","张军","朱允炆","朱元璋");

//定义一个开始抽奖函数

function chou(){

//当抽奖次数大于5时将所有框中的人名归空

if(numbers>5){

numbers=0;


}

if(numbers==0){

document.getElementById("one").value="";

document.getElementById("two1").value="";

document.getElementById("two2").value="";

document.getElementById("three1").value="";

document.getElementById("three2").value="";

document.getElementById("three3").value="";

}

   //给随机数变量赋值

   num=Math.round(Math.random()*(str.length-1));

//alert(num);

//alert(str);

 //给指定时间执行指定函数的变量赋值

 t=setTimeout("chou()",50);

 //给一个被抽到人名变量赋值

 m=str[num];

 //在抽奖框中滚动人名

document.getElementById("inpu").value=m;



//alert(m);

//setTimeout("chou()",100);

}

//setTimeout("chou()",100);

//chou();


//创建停止函数

function ting(){

  clearTimeout(t);

  //j+=1;

  //将获过奖的人名放到数组最后

  str[num]=str[str.length-1];

  //每执行一次抽奖就将人名数组长度减一,也就是将数组最后一个人名去掉

  str.length=str.length-j;

   

    //判断抽奖次数

  if(numbers==0){

  document.getElementById("one").value=m;

  }

  if(numbers==1){

  document.getElementById("two1").value=m;  

  }

  if(numbers==2){

  document.getElementById("two2").value=m;  

  }

  if(numbers==3){

  document.getElementById("three1").value=m;  

  }

  if(numbers==4){

  document.getElementById("three2").value=m;  

  }if(numbers==5){

  document.getElementById("three3").value=m;  

  }

 

  //if(numbers<=5){

   numbers+=1;

  // }

   //else{

    // alert("不能砸抽了");

   

   //}

   //alert(numbers);

   //alert(str.length);

   //alert(str);

   //当抽奖次数大于5时将所有框中的人名归空

   if(numbers>5){

   numbers=0;

   if(confirm("想从新再抽吗?那就刷新一下从新开始吧")){

     document.getElementById("kaishi").focus();

   

   }

  }

}




</script>


</head>



<body>


<form name="form">

<input  id="kaishi" type="button" value="开始" onClick="chou()"/>

<input id="inpu" type="text" />

<input name="" type="button" value="停止" onClick="ting()"/>

<table width="250" border="1" cellpadding="0" cellspacing="0" bordercolor="#FF0000">

  <tr>

    <th scope="row">一等奖:<input id="one" type="text" /></th>

  </tr>

</table>

<table width="250" border="1" cellpadding="0" cellspacing="0" bordercolor="#FF9933">

  <tr>

    <th width="74" rowspan="5" scope="row">二等奖:</th>

    <td width="170"><input id="two1" type="text" /></td>

  </tr>

  <tr>

    <td width="170"><input id="two2" type="text" /></td>

  </tr>

 

 

</table>

<table width="250" border="1" cellpadding="0" cellspacing="0" bordercolor="#3399CC">

  <tr>

    <th width="76" rowspan="3" scope="row">三等奖:</th>

    <td width="168"><input id="three1" type="text" /></td>

  </tr>

  <tr>

    <td width="168"><input id="three2" type="text" /></td>

 

  </tr>

  <tr>

    <td width="168"><input id="three3" type="text" /></td>

 

  </tr>

</table>



</form>

<p>

<div id="di" style="width:100; height:100">



</div><br>



</body>

</html>