温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么用jquery实现抽奖系统

发布时间:2021-08-06 23:43:13 来源:亿速云 阅读:131 作者:chen 栏目:web开发

本篇内容主要讲解“怎么用jquery实现抽奖系统”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么用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 ></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实现抽奖系统”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI