js摇奖用js做一个摇奖程序要求在0-10中抽出三个幸运号码且三个号码各不相同代码

JavaScript023

js摇奖用js做一个摇奖程序要求在0-10中抽出三个幸运号码且三个号码各不相同代码,第1张

var map={}

document.write("今日开奖号:<br />")

for(var i=0i<3i++){

var r=Math.floor(Math.random()*10)

if(null==map[r]){

document.write(r+"&nbsp")

map[r]=1

}else{

i--

continue

}

}

将就看下吧

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Document</title>

</head>

<body>

<button id="buySelef">买一张(自选)</button>

<button id="buyRandom">买一张(机选)</button>

<button id="result">买一张(开奖)</button>

<div id='resultList'>

<span>结果</span>

</div>

</body>

</html>

<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>

<script>

window.Prize={LotteryResults:0 }

$("#buySelef").click(function(){

var num = Math.floor(Math.random() * (300 - 100) ) + 100

$("#resultList").append('<p>自选结果:'+num+'<p>')

})

$("#buyRandom").click(function(){

var num = Math.floor(Math.random() * (300 - 100) ) + 100

$("#resultList").append('<p>机选结果:'+num+'<p>')

})

$("#result").click(function(){

if(window.Prize.LotteryResults<=0)

{

var num = Math.floor(Math.random() * (300 - 100) ) + 100

window.Prize.LotteryResults=num

}

else{

var num = window.Prize.LotteryResults

}

$("#result").append('<p>开奖结果:'+num+'<p>')

})

</script>