At the end of each company has a lottery, I also wrote a super simple code to achieve the lottery results, there is no gorgeous Css3 effect, but there are short and concise JS code. Core: JS's Math object and array object
Code
1 <!DOCTYPE HTML>2 <HTMLLang= "en">3 <Head>4 <MetaCharSet= "UTF-8">5 <title>Random</title>6 <style>7 #awardListDom{width:100%;}8 </style>9 </Head>Ten <Body> One <label for= "Awardlistdom">Awards List</label><BR> A <inputtype= "text"value=""ID= "Awardlistdom"> <BR> - <label for= "num">The prize that I drew</label><BR> - <inputtype= "text"value=""ID= "num"> <BR> the <ButtonID= "Submit">Start a lottery</Button> - <Script> - /* - * Ideas: Random draw, draw a prize will reduce a + * Math Object method: Http://www.w3school.com.cn/jsref/jsref_obj_math.asp - *-RANDOM (): Returns the random number between 0 and 1. + *-floor (): Get integer A * Array Operation: at *-Splice (x, y); X: Start position, y: Get and delete number - */ - - functionRandom (Min,max) { - returnmath.floor (min+math.random ()*(Max-min)); - } in varAwardlistdom=document.getElementById ("Awardlistdom"), - Num=document.getElementById ("Num"), to Submit=document.getElementById ("Submit"); + varawardlist=["First Prize","Second prize","Second prize","Third Prize","Third Prize","Third Prize","Encouragement Award","Encouragement Award","Encouragement Award","Encouragement Award","Thank you for participating","Thank you for participating","Thank you for participating","Thank you for participating","Thank you for participating","Thank you for participating"]; - the Awardlistdom.value=awardlist; * Submit.onclick=function(){ $ //referencing ArraysPanax Notoginseng varOldarray=awardlist; - varRnum=Random (0, oldarray.length); the + if(Oldarray.length<1){ A Awardlistdom.value="End of event"; the Num.value="End of event"; + } - Else{ $ Num.value=Oldarray[rnum]; $ Oldarray.splice (Rnum,1); - Awardlistdom.value=Oldarray; - } the } - </Script>Wuyi </Body> the </HTML>
Demo:http://2.liteng.sinaapp.com/javascript/award.html
Github:github:https://github.com/litengdesign/award
JS Simple Lottery Code