RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
JavaScript抽,javascript抽奖代码多行

有谁会用javascript编写一个抽签的代码啊。不能有重复抽同一个签的。一个是十个签

var arr = [1,2,3,4,5,6,7,8,9,10];//十个签,里边可以放任何数据

公司主营业务:成都做网站、网站制作、成都外贸网站建设、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联建站是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联建站推出兴安免费做网站回馈大家。

function getArr(arr){

var key = Math.round(Math.random() * (arr.length-1));

return arr.splice(key,1);//每抽一个,是真正从数组里取出,数组里少一个签,这样就不会重复了

}

alert(getArr(arr)[0]);

alert(getArr(arr)[0]);

alert(getArr(arr)[0]);

如何使用javascript做一个简单的抽奖程序

参考下面写的小程序,是一个跑马灯效果。

html

head

meta http-equiv="Content-Type" content="text/html; charset=utf-8" /

title抽奖/title

style

*{margin:0;padding:0;}

#box{width:400px;height:400px;border:2px #C6C solid;margin:20px auto;background:#99F;}

#boxdiv{position:absolute;width:60px;height:40px;color:#F03;font-size:20px;border:2px #F63 solid;opacity:0.4;line-height:40px;background:#F96;}

#butt{position:absolute;background:#F6C;color:#36F;font-size:16px;margin-top:200px;margin-left:150px;}

#span{width:300px;height:40px;margin-left:160px;display:block;border:2px #F63 solid;float:left;line-height:40px;}

#span i{font-style:normal;}

/style

/head

body

span id="span"离抽奖结束还有:i/ii/ii/ii/i/span

div id="box" class="box"

div一等奖/div

div style="margin-left:336px"二等奖/div

div style="margin-left:336px;margin-top:356px;"三等奖/div

div style="margin-top:356px;"安慰奖/div

button id="butt" onclick="butt()"点击抽奖/button

/div

script type="text/javascript"

var opa=document.getElementById("box").getElementsByTagName("div");

var ii=document.getElementById("span").getElementsByTagName("i");

for(var i=0;iopa.length;i++){

opa[i].style.opacity=0.4;

}

//var span=document.getElementById("span").style;

var i=0,

t,tt,r,

count1=1,//限制一等奖只中一次,当一等奖抽完后顺延到二等奖

count2=3,//限制二等奖只中3次,当二等奖抽完后顺延到三等奖

count3=10,//限制等奖只中10次

prize=1,//抽奖是否结束

time=200,

curr=0;//每次抽奖完成才能再次点击

var toDate = new Date(2016,7,29,19,55,0);

var dt,currDate;

function obtain(){//倒计时

currDate=new Date();

dt=Math.ceil((toDate.getTime()-currDate.getTime())/1000);!--转换成s--

ii[0].innerHTML=parseInt(dt/(24*60*60))+'天';

ii[1].innerHTML=Math.floor(dt%(24*60*60)/(60*60))+'时';

ii[2].innerHTML=Math.floor(dt%(24*60*60)%(60*60)/60)+'分';

ii[3].innerHTML=Math.floor(dt%60)+'秒';

if(dt=0){

prize=0;

ii[0].innerHTML=0+'天';ii[1].innerHTML=0+'时';ii[2].innerHTML=0+'分';ii[3].innerHTML=0+'秒';

if(prize==0s==0){alert("抽奖已结束");clearInterval(tt);}

}

}

tt=setInterval(obtain,1000);

function butt(){

curr++;

if(count1==0count2==0count3==0){

prize=0;

}

if(curr==1prize==1){

if(i!=0){

opa[i].style.opacity=0.4;

}

i=0;

clearInterval(t);

r=parseInt(Math.random()*10000)+1;//产生1-10000的随机数

//r=1;

opa[i].style.opacity=1;

t=setInterval(move,time);

}else if(curr!=1prize==1){alert("请等待本次抽奖完成再抽奖");alert("请点击确定继续");}

else if(prize==0){alert("抽奖已结束");}

}

/*function move(r){

switch(r){

case 1:

}

}*/

function move(){

opa[i].style.opacity=0.4;

if(iopa.length-1){

i++;

}else{i=0;}

opa[i].style.opacity=1;

time+=50;

console.log("r="+r+","+"time="+time);

if(r==1count10){//中一等奖

clearInterval(t);

t=setInterval(move,time);

if(time==800){

clearInterval(t);

time=200;

count1--;

curr=0;

console.log("中一等奖的次数还有:"+count1+"次");

}

}else if((r%2999==0||r==1count1==0)count20){//中二等奖

clearInterval(t);

t=setInterval(move,time);

if(time==850){

count2--;

clearInterval(t);

time=200;

curr=0;

console.log("中二等奖的次数还有:"+count2+"次");

}

}else if((r%1000==0||r%2999==0count2==0||r==1count1==0)count30){//中三等奖

clearInterval(t);

t=setInterval(move,time);

if(time==900){

time=200;

count3--;

clearInterval(t);

curr=0;

console.log("中三等奖的次数还有:"+count3+"次");

}

}else{//安慰奖

clearInterval(t);

t=setInterval(move,time);

if(time==950){

clearInterval(t);

curr=0;

time=200;

}

}

}

/script

/body

/html

使用JavaScript完成一个抽奖程序,当单击页面上开始抽奖按钮时,在1~36中选取7个互不相同

1~36个数取7个不同的,需要用while循环+随机数去取出7个数。

在while循环里面,可以判断取出来的数(用switch),是否是28,18,8. 如果有输出相应的奖项,如果没有,就输出其它的。然后将这7个数,打印出来就好了。

JavaScript(缩写为JS)是一种高级的、多范式、解释型的编程语言,是一门基于原型、函数先行的语言,它支持面向对象编程、命令式编程以及函数式编程。

它提供语法来操控文本、数组、日期以及正则表达式,不支持I/O(比如网络、存储和图形等),但可以由它的宿主环境提供支持。它已经由ECMA(欧洲计算机制造商协会)通过ECMAScript实现语言的标准化。它被世界上的绝大多数网站所使用,也被世界主流浏览器支持。

谁能帮我设计一个用javascript 做一个随机抽题的东西

SCRIPT LANGUAGE="JavaScript"

function Tnumberon(beingNum, Num) {

var TempNum= new Array();

var RetunSrt = new Array();

var ChosenNumber;

if (NumbeingNum) {

Num = beingNum;

}

for (var i = 0; i=beingNum; i++) {

TempNum[i] = i;

}

for (var i = beingNum; ibeingNum-Num; i--) {

ChosenNumber = Math.floor(Math.random()*i);

RetunSrt[beingNum-i] = TempNum[ChosenNumber];

TempNum[ChosenNumber] = TempNum[i];

}

return RetunSrt;

}

/SCRIPT

a href='javascript:document.write(Tnumberon(9,3))'Tnumberon(题库总数,要抽题数)/a

javascript 随机抽取 一组数字(设为M)中的N(N

script language="JavaScript" type="text/javascript"

var a=["a","b","c","d","e","f","g","h","i","j","k","l"];

var s =parseInt(Math.random()*12)+1;

alert(a[s]);

/script

js实现可键盘控制的简单抽奖程序

本文实例为大家分享了js抽奖程序的编写代码,以及编写注意事项,感兴趣的小伙伴们可以参考一下

代码:

!DOCTYPE

html

html

lang="en"

head

meta

charset="UTF-8"

title简单抽奖(可用键盘)/title

style

*{margin:0;padding:0;}

.box{width:

400px;height:

300px;margin:50px

auto;background:

red}

.title{color:

#fff;font-size:

30px;font-weight:700px;padding:

50px

0;text-align:

center;height:40px;}

.btm{text-align:

center;padding:20px

0;}

.btm

a{display:

inline-block;width:

120px;height:60px;line-height:

60px;background:

#FEF097;margin:0

10px;text-decoration:

none;}

/style

script

var

data=['Iphone','Ipad','笔记本','相机','谢谢参与','充值卡','购物券'],

timer=null,//定时器

flag=0;//阻止多次回车

window.onload=function(){

var

play=document.getElementById('play'),

stop=document.getElementById('stop');

//

开始抽奖

play.onclick=playFun;

stop.onclick=stopFun;

//

键盘事件

document.onkeyup=function(event){

event

=

event

||

window.event;

//

回车键的code值:13

if(event.keyCode==13){

if(flag==0){

playFun();

flag=1;

}else{

stopFun();

flag=0;

}

}

}

function

playFun(){

var

title=document.getElementById('title');

var

play=document.getElementById('play');

clearInterval(timer);

timer=setInterval(function(){

var

random=Math.floor(Math.random()*data.length);

title.innerHTML=data[random];

},60);

play.style.background='#999';

}

function

stopFun(){

clearInterval(timer);

var

play=document.getElementById('play');

play.style.background='#FEF097';

}

}

/script

/head

body

div

class="box"

div

class="title"

id="title"淘家趣抽奖/div

div

class="btm"

a

href="javascript:;"

id="play"开始/a

a

href="javascript:;"

id="stop"停止/a

/div

/div

/body

/html

注意点:

1.随机数,取数组的其中一个;取0-n之间:Math.random()*(n+1)

2.定时器,开始抽奖时要停止前面的一次抽奖,不然会定时器重叠

3.按键操作,要判断是抽奖进行中,还是未开始,所有设置了变量

flag

想要学习更多关于javascript抽奖功能,请参考此专题:javascript实现抽奖功能

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。


分享题目:JavaScript抽,javascript抽奖代码多行
文章链接:http://sczitong.cn/article/dsesdhg.html