<!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>
就是个元素选择 点击触发按钮 全选$('x').attr('checked', 'checked')奇数$('x:nth-child(n+1)')偶数$('x:nth-child(n+2)') 情空$('x').attr('checked', '')就那么个意思 错了别怪我