怎么用jquery实现抽奖系统-创新互联

本篇内容主要讲解“怎么用jquery实现抽奖系统”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么用jquery实现抽奖系统”吧!

10年积累的成都网站设计、成都做网站经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站设计制作后付款的网站建设流程,更有龙山免费网站建设让你可以放心的选择与我们合作。

闲来无事做了一个抽奖的系统:


<!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 ></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>


试用效果还可以.如图:

    怎么用jquery实现抽奖系统

到此,相信大家对“怎么用jquery实现抽奖系统”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。

新闻名称:怎么用jquery实现抽奖系统-创新互联
文章URL:https://www.cdcxhl.com/article34/dgcjpe.html

成都网站建设公司_创新互联,为您提供云服务器Google企业网站制作全网营销推广网页设计公司定制网站

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

营销型网站建设