jquery實現抽獎系統

來源:互聯網
上載者:User

jquery實現抽獎系統
閑來無事做了一個抽獎的系統:

    <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>抽獎系統</title><script src="source/jquery.js"></script><style>#box{width:450px;margin:0 auto;}.show{width:100px;height:55px;text-align:center;background:#ff0;line-height:55px;border:1px solid #000;border-radius:5px;font-size:20px;font-family:微軟雅黑;float:left;margin:5px 5px 0px 5px;}#person{width:450px;height:100px;background:#ff0;text-align:center;line-height:100px;font-size:45px;margin:0 auto;margin-top:25px;border:1px dotted #000;font-family:楷體;border-radius:10px;}p{margin-top:25px;text-align:center;}button{width:65px;height:35px;text-align:center;border:0px;border-radius:5px;background:#f36;font-size:16px;color:#fff;cursor:pointer;}.active{background:#f00;}</style></head><body><div id='box'><div class="show">吳澤輝</div><div class="show">李景亮</div><div class="show">李志偉</div><div class="show">潘雅靜</div><div class="show">王建華</div><div class="show">高強</div><div class="show">秦英</div><div class="show">高文幸</div><div class="show">李雪</div><div class="show">高丹</div><div class="show">崔小剛</div><div class="show">趙豔萍</div><div class="show">於曉麗</div><div class="show">于洋</div><div class="show">胡小萌</div><div class="show">武淵</div></div><div style="clear:both"></div><div id="person">獲獎者</div><p><button id="btn">開始</button></p></body><script>var showlen=$('.show').length; //擷取人員總數var time=null; //初始化計時器$('#btn').click(function(){var flag=$(this).html();flag=flag=='開始'?'停止':'開始'; //交換按鈕上的內容$(this).html(flag);switch(flag){case '停止': //這裡是開始作抽獎getIndex(0);break;case '開始': //這裡是停止迴圈getIndex(1);$('#person').html('恭喜:'+$("#person").html()); //彙報結果break;}});function getIndex(mark){if(mark==1){clearInterval(time); //終止計時器}else{time=setInterval(show,1); //開啟計時器}function show(){var idx=Math.floor(Math.random()*showlen); //產生隨機數for(var i=0;i<showlen;i++){$('.show').eq(i).css({'background':'#ff0'}); //去掉所有的背景色}$('.show').eq(idx).css({'background':'#f00'});  //為當前選中的人加背景色$("#person").html($('.show').eq(idx).html());  //將當前選中的人的名字顯示在下面的框內}}</script></html>

 


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.