本篇內(nèi)容主要講解“怎么用jquery實現(xiàn)抽獎系統(tǒng)”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“怎么用jquery實現(xiàn)抽獎系統(tǒng)”吧!
閑來無事做了一個抽獎的系統(tǒng):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>抽獎系統(tǒng)</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">高強(qiáng)</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 ></div>
<div id="person">
獲獎?wù)?/p>
</div>
<p>
<button id="btn">開始</button>
</p>
</body>
<script>
var showlen=$('.show').length; //獲取人員總數(shù)
var time=null; //初始化計時器
$('#btn').click(function(){
var flag=$(this).html();
flag=flag=='開始'?'停止':'開始'; //交換按鈕上的內(nèi)容
$(this).html(flag);
switch(flag)
{
case '停止': //這里是開始作抽獎
getIndex(0);
break;
case '開始': //這里是停止循環(huán)
getIndex(1);
$('#person').html('恭喜:'+$("#person").html()); //匯報結(jié)果
break;
}
});
function getIndex(mark)
{
if(mark==1)
{
clearInterval(time); //終止計時器
}
else
{
time=setInterval(show,1); //開啟計時器
}
function show()
{
var idx=Math.floor(Math.random()*showlen); //生成隨機(jī)數(shù)
for(var i=0;i<showlen;i++)
{
$('.show').eq(i).css({'background':'#ff0'}); //去掉所有的背景色
}
$('.show').eq(idx).css({'background':'#f00'}); //為當(dāng)前選中的人加背景色
$("#person").html($('.show').eq(idx).html()); //將當(dāng)前選中的人的名字顯示在下面的框內(nèi)
}
}
</script>
</html>
試用效果還可以.如圖:
到此,相信大家對“怎么用jquery實現(xiàn)抽獎系統(tǒng)”有了更深的了解,不妨來實際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
新聞名稱:怎么用jquery實現(xiàn)抽獎系統(tǒng)-創(chuàng)新互聯(lián)
文章URL:http://www.rwnh.cn/article34/dgcjpe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器、Google、企業(yè)網(wǎng)站制作、全網(wǎng)營銷推廣、網(wǎng)頁設(shè)計公司、定制網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容