基本信息
源码名称:js 抽奖例子 源码下载
源码大小:2.36KB
文件格式:.html
开发语言:CSS
更新时间:2016-10-31
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 5 元 
   源码介绍

    var data = ['Phone5', 'Ipad', '三星笔记本', '佳能相机', '惠普打印机', '谢谢参与', '50元充值卡', '1000元超市购物券', '我的手机'],
        timer = null;
        var flag=0;
    window.onload = function() {

        var play = document.getElementById('play');
        var stop = document.getElementById('stop');
        play.onclick = playfun;
        stop.onclick = stopfun;
        //按下键盘事件
       
        document.onkeyup = function(event) {
            var e = event || window.event;
            var c = e.keyCode;
            if(c===13){
            if(flag==0){
            playfun();
            flag=1;
            }else{
            stopfun();
            flag=0;
            }
            }
           
        }
    }

    function playfun() {

        var title = document.getElementById('title');
        clearInterval(timer)
        timer = setInterval(function() {
            var random = Math.floor(Math.random() * data.length)
            title.innerHTML = data[random];
        }, 100);
        play.style.backgroundColor = 'red';
    }

    function stopfun() {
    
        clearInterval(timer);
        play.style.backgroundColor = 'blue';
       
    }