美文网首页
双色球代码

双色球代码

作者: 疯也是一种态度_ | 来源:发表于2019-10-16 21:25 被阅读0次
        <style>
        #content span {
            width: 60px;
            height: 60px;
            display: inline-block;
            line-height: 60px;
            text-align: center;
            border: solid 3px red;
            border-radius: 50%;
            font-size: 30px;
        }
        #content span:last-child {
            background-color: blue;
        }
    </style>
    </head>
    
    <body>
    <div id="content"></div>
    <button id="start">开始</button>
    <button id="end">结束</button>
    </body>
    <script>
    var content = document.querySelector('#content')
    var start = document.querySelector('#start')
    var end = document.querySelector('#end')
    function getNums(start, end, many) {
        var arr = []
        while (arr.length < many) {
            var num = Math.floor(Math.random() * (end - start + 1) + start)
            num = num < 10 ? '0' + num : num
            if (arr.indexOf(num) == -1) {
                arr.push(num)
            }
        }
        arr.sort(function (a, b) {
            return a - b
        })
        return arr
    }
    getHtml()
    function getHtml() {
        var str = ''
        var red = getNums(1, 33, 6)   // 获取红球
        var blue = red.concat(getNums(1, 16, 1))  // 获取篮球
        for (var i in blue) {
            str += `<span>${blue[i]}</span>`
        }
        content.innerHTML = str
    }
    var timer = null
    start.onclick = function () {
        timer = setInterval(getHtml, 50)
        start.disabled = true
    }
    end.onclick = function () {
        clearInterval(timer)
        timer = null
        start.disabled = false
    }
    </script>

    相关文章

      网友评论

          本文标题:双色球代码

          本文链接:https://www.haomeiwen.com/subject/djkpmctx.html