zoukankan      html  css  js  c++  java
  • javascript-抽奖

    var data = ['Phone5','Ipad','三星笔记本','佳能相机','惠普打印机','谢谢参与','50元充值卡','1000元超市购物券'],
        timer = 0,
        num = 0;
    window.onload = function(){
      var title = document.getElementById('title'),
          play = document.getElementById('play'),
          stop = document.getElementById('stop');
     
      play.onclick = function(){
        playFun(title, play);
      };
      stop.onclick = function(){
        stopFun(play);
      };
      document.onkeyup = function(e){
        e = e || window.event;
        if(e.keyCode == 13){
          if(num === 0){
            playFun(title,play);
            num = 1;
          }else{
            stopFun(play);
            num = 0;
          }
        }
      }
    };
     
    function playFun(tit, node){
      clearInterval(timer);
      timer = setInterval(function(){
        tit.innerHTML = data[Math.floor(Math.random()* data.length)];
      },50);
      node.style.backgroundColor = '#999';
    }
     
    function stopFun(node){
      clearInterval(timer);
      node.style.backgroundColor = '#369';
    }
  • 相关阅读:
    时钟展频技术能有效降低EMI,深入讲解展频发生器!
    24:购物单
    22:按照字典输出字符串
    21:句子逆序
    20:字符反转
    19:ReverseNumber数字颠倒
    DNS原理及其解析过程
    18:字符个数统计
    17:不重复整数提取NoRepeatNum
    \s+ split替换
  • 原文地址:https://www.cnblogs.com/sunhw360/p/4139812.html
Copyright © 2011-2022 走看看