基于javascript實(shí)現(xiàn)簡(jiǎn)單的抽獎(jiǎng)系統(tǒng)
來(lái)源:易賢網(wǎng) 閱讀:1029 次 日期:2016-07-15 14:46:06
溫馨提示:易賢網(wǎng)小編為您整理了“基于javascript實(shí)現(xiàn)簡(jiǎn)單的抽獎(jiǎng)系統(tǒng)”,方便廣大網(wǎng)友查閱!

這篇文章主要為大家詳細(xì)介紹了基于javascript實(shí)現(xiàn)簡(jiǎn)單的抽獎(jiǎng)系統(tǒng),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了js實(shí)現(xiàn)簡(jiǎn)單的抽獎(jiǎng)系統(tǒng),供大家參考,具體內(nèi)容如下

<!doctype html>

<html lang="en">

<head>

  <meta charset="gb2312">

  <title>抽獎(jiǎng)活動(dòng)</title>

  <style>

*{

 margin:0;padding:0;

}

#title{

 color:red;text-align:center;margin:0 auto;width:240px;height:70px;padding-top:10px;background:opacity(0);

}

.btns{

 width:190px;height:30px;margin:0px auto;

}

.btns span{

 display:block;float:left;width:80px;height:28px;text-align:center;background:#036;color:#fff;cursor:pointer;border:1px solid #eee;border-radius:8px;font-family:"微軟雅黑";font-size:14px;line-height:28px;margin-right:10px;

}

#txt{

 font-size:14px;color:#ccc999;text-align:center;margin:0 auto;width:190px;height:50px;padding-top:10px;

}

  </style>

  <script>

 var mytype=["iPhone6s","iPad Air2","DELL外星人","鍵鼠套裝","1000元超市購(gòu)物卡","200元話費(fèi)充值卡","謝謝參與","品牌耳機(jī)","港澳臺(tái)7日游","50元優(yōu)惠券"],//定義獎(jiǎng)品池

   timer=null,

   count=0;

//加載時(shí)觸發(fā)

 window.onload=function(){

 var start = document.getElementById("start");

 var stop = document.getElementById("stop");

 start.onclick=startFun;//這個(gè)函數(shù)后面加括號(hào),就直接調(diào)用了該函數(shù),所以不要加

 stop.onclick=stopFun;

 //綁定鍵盤事件

 document.onkeyup=function(e){

   e = e || window.event;

  if(e.keyCode==13){

    if(count==0){

    startFun();

    count=1;

    }

  else{  

    stopFun();

    count=0;

    }

  }

 }

 }

//點(diǎn)擊開(kāi)始,標(biāo)題欄開(kāi)始輪動(dòng)

 function startFun(){

  clearInterval(timer);//開(kāi)始時(shí),清除計(jì)時(shí)器,避免二次觸發(fā)

  var title = document.getElementById("title");

  var start = document.getElementById("start");

  timer = setInterval(function(){

    var num= Math.floor(Math.random()*mytype.length);

    title.innerHTML=mytype[num];

  },50);

  start.style.background="#ccc";

 }

 //點(diǎn)擊停止,標(biāo)題欄停止輪動(dòng)并輸出輪動(dòng)結(jié)果

 function stopFun(){

  var start = document.getElementById("start"),

    txt = document.getElementById("txt"),

    title = document.getElementById("title");

  clearInterval(timer);//清除計(jì)時(shí)器,停止計(jì)時(shí)器

  start.style.background="#036";

 }

  </script>

<body>

 <div>

 <h2 id="title">開(kāi)始抽獎(jiǎng)!</h2>

 </div>

 <div class="btns">

 <span id="start">開(kāi)始</span>

 <span id="stop">停止</span>

 </div>

 <div id="txt">支持回車鍵(Enter)開(kāi)始/停止。</div>

</body>

</html>

效果圖:

名單

更多信息請(qǐng)查看網(wǎng)絡(luò)編程
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

2026國(guó)考·省考課程試聽(tīng)報(bào)名

  • 報(bào)班類型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)