JS变成随机抽号怎么写?

2025-04-24 07:49:48
推荐回答(1个)
回答1:





MODEL PAGE

table {
margin: 0 auto;
border: 1px solid black;
border-collapse: collapse;
border: 1px solid black;
}

td {
border: 1px solid black;
}


var draw =
    {
        timer : null,
        sleep : 60,
        rnd : '000000000',
        init : function ()
        {
        var lottery = this.lottery = document.getElementById ("lottery");
        var tr = lottery.insertRow (0);
        var arr = this.arr = this.rnd.split ('');
        for ( var i = 0; i < arr.length; i++)
        {
        var td = tr.insertCell (tr.cells.length);
        var n = document.createTextNode (arr[i]);
        td.appendChild(n);
        }
        var cell = lottery.rows[lottery.rows.length - 1].cells[0];
        cell.style.textAlign = 'center';
        cell.colSpan = arr.length;
        cell.children[0].onclick = this.start;
        cell.children[1].onclick = this.stop;
        },
        start : function ()
        {
        if (!draw.timer)
        {
         draw.timer = setInterval (function ()
        {
        for ( var i = 0; i < draw.arr.length; i++)
        {
        draw.lottery.rows[0].cells[i].childNodes[0].nodeValue = Math.floor (Math.random () * 10);
        }
        }, draw.sleep);
        }
        },
        stop : function ()
        {
        if (!!draw.timer)
        {
        clearInterval (draw.timer);
        draw.timer = null;
        }
        }
    };
    
    window.onload = function ()
    {
    draw.init ();
    }