JS 抽奖

<style>
    #abc {
        width:300px;
        height:200px;
        margin: 0 auto;
        border:solid 1px #ddd;
        text-align:center;
        font-size:30px;
        line-height:200px;
    }

    #buts {
        width:300px;
        height:auto;
        text-align:center;
        margin:0 auto;
    } 
</style>
<div id="abc">小A</div>
<div id="buts">
    <button id="start">开始</button>
    <button id="stop">停止</button>
</div>

<script type="text/javascript">
var stop = document.getElementById('stop');
var names = ['小A','小B','小C','小D','小E','小F','小G','小H','小I','小O'];
var inte = null;
//开启定时器
start.onclick = function() {
    //判断定时器是否已经存在
    if(inte != null) return;
    inte = setInterval(function(){
        //获取随机的索引
        var index = rand(0, names.length-1);
        //获取名称
        var name = names[index];
        //设置
        abc.innerHTML = name;
    },100);
}

function rand(m,n) {
    return Math.ceil(Math.random()*(n-m+1)) + m-1;
}

//停止定时器
stop.onclick = function() {
    clearInterval(inte);
    inte = null;
}
</script>