JS编写的抽奖程序
公司要开年会了,我这里要做个抽奖程序,我一直没怎么接触过JS,憋了半天,憋出个这样的程序:
<html>
<head>
<title> Untitled Document </title>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<style type= "text/css ">
<!--
.unnamed1 {
height: 150px;
width: 200px;
border: 0px none;
font-size: 100px;
font-weight: bolder;
color: #FF0000;
text-align: center;
}
-->
</style>
</head>
<script language= "javascript ">
var con= 'start ';
function showme(){
if (con== 'start ')
{document.form.textfield.value= '0 ' + Math.round(Math.random()*500);
timeid=setTimeout( 'showme() ',50);}
}
function startshowme(){
con= 'start ';
showme();
}
function stopshowme(){
con= 'stop ';
}
</script>
<body>
<p> </p>
<p> <br>
</p>
<table width= "100% " border= "0 " align= "center " cellpadding= "0 " cellspacing= "0 ">
<tr>
<td align= "center "> <form name= "form " method= "post " action= " ">
<input name= "textfield " type= "text " class= "unnamed1 " onFocus= "this.blur() " size= "30 ">
</form> </td>
</tr>
<tr>
<td align= "center "> <input type= "button " name= "Button " value= "开始 " onClick= "startshowme() ">
<input type= "button " name= "Button " value= "终止 " onClick= "stopshowme() "> </td>
</tr>
</table>
</body>
</html>
现在有这样的问题想请教各位
1.抽过的号码不能重复
2.数字一直保持 在3位,比如001,020,140这样的
由于比较急,所以希望各位能给出代码谢谢了
------解决方案-------------------- <html>
<head>
<title> Untitled Document </title>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<style type= "text/css ">
<!--
.unnamed1 {
height: 150px;
width: 200px;
border: 0px none;
font-size: 100px;
font-weight: bolder;
color: #FF0000;
text-align: center;
}
-->
</style>
</head>
<script language= "javascript ">
var con= 'start ';
var value = 0;
var valueArray = new Array();
function showme() {
if (con== 'start ') {
do {
value = Math.round(Math.random()*4 + 1);
if ( value < 10 )
value = "00 " + value;
if ( value < 100 )
value = "