Html
<label for= "awardlistdom" > Awards list </label><br><input type= "text" value= "" id= "Awardlistdom" > <br><label for= "num" > Drawn award </label><br><input type= "text" value= "" id= "num" > <br> <button id= "Submit" > Start draw </button>
Js
<script> function Random (Min,max) { return Math.floor (Min+math.random () * (max-min)); } var Awardlistdom=document.getelementbyid ("Awardlistdom"), Num=document.getelementbyid ("num"), submit= document.getElementById ("submit"); var awardlist=["First Prize", "Second Prize", "Second Prize", "Third Prize", "Third Prize", "Third prize", "Encouragement Award", "Encouragement Award", "Encouragement Award", "Encouragement Award", "Thank You for participation", "Thank You for participation", "Thank You for participation", "Thank you for participating" Thank you for participating "]; Awardlistdom.value=awardlist; Submit.onclick=function () { //reference array var oldarray=awardlist; var rnum=random (0,oldarray.length); if (oldarray.length<1) { awardlistdom.value= "activity ends"; Num.value= "activity ends"; } else{ Num.value=oldarray[rnum]; Oldarray.splice (rnum,1); Awardlistdom.value=oldarray; } } </script>
Core:
JS's Math object and array object
Ideas:
1. Draw a prize and reduce a 2.Math object method: Http://www.w3school.com.cn/jsref/jsref_obj_math.asp 3.-random (): Returns the random number between 0 and 1. 4.-floor (): Get integer
Array operations:
-Splice (x, y); X: Start position, y: Get and delete number
JS Draw function Code