コア:JSの数学オブジェクトと配列オブジェクト
<!doctype html> <html lang = "en"> <head> <meta charset = "utf-8"> <title>ランダム</title </title> <style> #awardlistdom {width:100%;} </style> </head> <body> <label for = "awardlistdom" <br> <label for="num"> Awards won</label><br> <input type="text" value="" id="num"> <br> <button id="submit">Start the lottery</button> <script> /* * Idea: Random lottery, draw a prize and reduce one * Math object method: http://www.w3school.com.cn/jsref/jsref_obj_math.asp * -random():0から1の間の乱数を返します。 X:start position、y:number*/ function random(min、max)を取得して削除します{return math.floor(min+math.random()*(max-min)); } var awardListdom = document.getElementById( "ardlistdom")、num = document.getElementById( "num")、submit = document.getElementById( "submit"); var awardlist = ["Fiond Prize"、 "2番目の賞品]、「2番目の賞」、「3番目の賞」、「3番目の賞」、「3番目の賞」、「3番目の賞」、「励まし賞」、「励まし賞」、「励まし賞」、「励まし賞」、「参加をありがとう」、「参加をありがとう」、「感謝」「感謝」「感謝」」 awardlistdom.value = awardlist; submit.onclick = function(){//参照配列var oldarray = awardlist; var rnum = random(0、oldarray.length); if(oldArray.length <1){awardlistdom.value = "event end"; num.value = "イベントエンド"; } else {num.Value = oldArray [rnum]; OldArray.splice(rnum、1); awardlistdom.value = oldArray; }} </script> </body> </html>デモ:http://demo.vevb.com/js/2015/choujiang/
github:https://github.com/litengdesign/award