代碼如下:
<style type="text/css">
div {font-weight: bold;text-align: center;}
.tone{width: 30px;height:30px;border: 2px solid #ff5151;border-radius: 18px;float: left;
font-size: 14px;color:#000000;color:#ff5959;line-height: 30px;margin-left: 5px;}
#tone6{border:2px solid #3ea1f4;color: #3ea1f4;}
#clickme{width: 120px;height: 25px;margin-top: 5px;margin-left: 20px;}
</style>
<div >
<div id="tone0" ></div>
<div id="tone1" ></div>
<div id="tone2" ></div>
<div id="tone3" ></div>
<div id="tone4" ></div>
<div id="tone5" ></div>
<div id="tone6" ></div>
</div>
<button type="button" id="clickme" onclick="run()">點我生成雙色球</button>
<script type="text/javascript">
function run(){
var reds=[parseInt(Math.random()*32+1)];
var blues=parseInt(Math.random()*15+1);
while(reds.length<6){
var r=parseInt(Math.random()*32);
//回圈遍歷reds陣列
for(var i=0;i<reds.length;i++){
if(reds[i]==r){
break;
}else if(i==reds.length-1){
reds.push(r);
//console.log(reds);
}
}
}
for(var j=0;j<reds.length;j++){
document.getElementById("tone"+j+'').innerHTML=reds[j];
}
document.getElementById("tone6").innerHTML=blues;
}
run();
</script>
效果如下:

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/204757.html
標籤:其他
上一篇:微信公眾號分享給朋友onMenuShareAppMessage失效 -cyy
下一篇:首尾元素偽類選擇_偽類選擇唯一子元素_根據元素編號靈活選擇_元素尾部偽類選擇_not排除選擇器_通過表單偽類創建個性化表單_文本偽類 -cyy
