javascript 双色球选号

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 双色球选号相关的知识,希望对你有一定的参考价值。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>双色球选号</title>
    <style type="text/css">
        .div1{
            width:300px;
            height:450px;
            margin-left:480px;
            margin-top: 50px;
            text-align: center;
        }

        td{
            border-color: grey;
            border-style: outset;
            width:40px;
            height: 40px;
            text-align: center;
        }

    </style>
</head>
<body>

    <div class="div1">
        <h3>双色球选号系统</h3>

        <table>
            <tr><td>01</td> <td>02</td> <td>03</td> <td>04</td> <td>05</td> <td>06</td></tr>
            <tr><td>07</td> <td>08</td> <td>09</td> <td>10</td> <td>11</td> <td>12</td></tr>
            <tr><td>13</td> <td>14</td> <td>15</td> <td>16</td> <td>17</td> <td>18</td></tr>
            <tr><td>19</td> <td>20</td> <td>21</td> <td>22</td> <td>23</td> <td>24</td></tr>
            <tr><td>25</td> <td>26</td> <td>27</td> <td>28</td> <td>29</td> <td>30</td></tr>
            <tr><td>31</td> <td>32</td> <td>33</td>
        </table>
        <br/>
        <button id="s1" onClick="start()">开始选号</button>
    </div>


</body>
</html>

<script>
    var s1=document.getElementById("s1");
    var td=document.getElementsByTagName("td");
    var reds=new Array();
    var blue=new Array();
    var timer;
    var timer1;
    function start() {
        reds.length=0;
        blue.length=0;
        for(var i=0;i<td.length;i++){
            td[i].style.backgroundColor="white";
        }
        window.clearInterval(timer1);
        s1.innerText="开始选号"
        timer=window.setInterval("work()",250);
        s1.innerText="选号中";
    }

    function work() {
        if(reds.length<6){
           var num=parseInt(Math.random()*td.length);
            var flag=true;
            if(reds.length==0){
                reds.push(num);
                td[num].style.backgroundColor="red";
            }
            for(var i=0;i<reds.length;i++){
                if(num==reds[i]){
                    flag=false;
                }
            }
            if(flag){
                reds.push(num);
                td[num].style.backgroundColor="red";
            }
        }else{
            if(blue.length==0){
                var b1=parseInt(Math.random()*16+1,10);
                blue.push(b1);
                for(var i=0;i<reds.length;i++){
//                    alert("红:"+reds+"蓝:"+b1);
                    if(b1==reds[i]){
                        start1();
                    }else{
                        td[b1].style.backgroundColor="blue";
                    }
                }
            }else{
                window.clearInterval(timer);
                s1.innerText="继续选号"
            }
        }
    }

    var colors = new Array("red","blue");
    var count=0;
    function repeat() {
        count++;
        var num=count%2;
        td[blue[0]].style.backgroundColor=colors[num];
    }
    
    function start1() {
        timer1=window.setInterval("repeat()",280);
    }

</script>


以上是关于javascript 双色球选号的主要内容,如果未能解决你的问题,请参考以下文章

PHP实现简单的双色球机选号码

使用Java数组实现双色球选号

彩票双色球中奖的几率是多少?谁算过?

JS动效--双色球

Java模拟生成双色球

双色球中5个红号的几率是多少?