Simple version:


      
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="Width = device - width, initial - scale = 1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>demo</title>
</head>
<body>
    <button>start</button>
    <button>stop</button>
    <p></p>
</body>
<script>
var btn=document.querySelectorAll("button") [0];
var btn1 = document.querySelectorAll("button") [1];
var p=document.querySelector("p");
var timer=null;
var arrs = ["First Prize"."Second prize"."Third prize"."Thank you"."Grand Prize"];
btn.onclick=(a)= >{ timer = setInterval((a)= > {
clearInterval(timer);
var arr = arrs[Math.floor(Math.random() * arrs.length)]; p.innerHTML = arr; }, 10); }
btn1.onclick=(a)= >{ clearInterval(timer) }
</script>
</html>
Copy the code

Updated version


      
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
    * {
        margin: 0;
        padding: 0;
    }
    .title {
        font-size: 24px;
        font-weight: bold;
        width: 400px;
        height: 70px;
        margin: 0 auto;
        padding-top: 30px;
        text-align: center;
        color: #f00;
    }
    .btns {
        width: 190px;
        height: 30px;
        margin: 0 auto;
    }
    .btns span {
        font-family: Microsoft Yahei;
        font-size: 14px;
        line-height: 27px;
        display: block;
        float: left;
        width: 80px;
        height: 27px;
        margin-right: 10px;
        cursor: pointer;
        text-align: center;
        color: #fff;
        border: 1px solid #eee;
        border-radius: 7px;
        background: # 036;
    }
    </style>
</head>

<body>
    <div id="title" class="title">The lottery is on!</div>
    <div class="btns">
        <span id="play">beginning</span>
        <span id="stop">Stop check</span>
    </div>
</body>
<script type="text/javascript">
var data = ['Phone7'.'Ipad'.'Samsung Notebook'.Canon camera.'HP Printer'.'Thanks for playing'.'100 yuan Top-up Card '.'1000 Yuan supermarket Coupon '],
    timer = null./ / timer
    flag = 0; // For keyboard event status flags

window.onload = function() {

    var play = document.getElementById('play'),
        stop = document.getElementById('stop');

    // Start the lottery
    play.onclick = playFun;
    stop.onclick = stopFun;

    // Keyboard events
    document.onkeyup = function(event) {
        event = event || window.event;
        if (event.keyCode == 13) {
            if (flag == 0) {
                playFun();
                flag = 1;
            } else {
                stopFun();
                flag = 0; }}}}// Start the lottery
function playFun() {
    var title = document.getElementById('title');
    var play = document.getElementById('play');
    // Each time clear the previous timer task, to avoid the cumulative frequency of the lottery effect will become faster and faster
    clearInterval(timer);
    timer = setInterval(function() {
        var random = Math.floor(Math.random() * data.length);
        title.innerHTML = data[random];
    }, 50);
    play.style.background = '# 999';
}
// Stop the lottery
function stopFun() {
    clearInterval(timer);
    var play = document.getElementById('play');
    play.style.background = '# 036';
}
</script>

</html>
Copy the code