建站软件 优化软件 编程软件 网页辅助 站群程序 网站程序 图像处理 资源教程 字体下载 推荐软件


您的位置:首页 > javascript学习 > 用javascript实现抽奖效果

用javascript实现抽奖效果

时间:2015-09-20 13:44:42  来源:免费模板网 作者:风雪 阅读次数 tags效果

有时候项目需要弄个随即抽奖的效果,用javascript怎么实现呢,效果如下


<html>
<title>模拟抽奖</title>
<head>
<meta name="keywords" content="freemoban.com">
<meta http-equiv=Content-Type content="text/html; charset=gb2312">
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
var alldata = "linkweb,blueidea,csdn,google,baidu,msn,qq,cctv,microsoft,adobe" //抽奖的姓名,以,为分隔
 
var alldataarr = alldata.split(",")
var num = alldataarr.length-1
var timer
function change(){
document.getElementById("oknum").value = alldataarr[GetRnd(0,num)];
}
 
function start(){
clearInterval(timer);
timer = setInterval('change()',50); //50(毫秒)为变换间隔,越小变换的越快
}
 
function ok(){
clearInterval(timer);
}
 
function GetRnd(min,max){
return parseInt(Math.random()*(max-min+1));
}
</SCRIPT>
模拟抽奖:<input type="text" id="oknum" name="oknum" value="">
<button onclick="start()" accesskey="s">开始(<U>S</U>)</button> 
<button onclick="ok()" accesskey="o">停止(<U>O</U>)</button>
</body>
</html>

是不是很有趣

本文地址:https://www.freemoban.com/javascript/2015/0920/2466.html

猜你喜欢
栏目推荐
模板推荐

Copyright:www.freemoban.com 免费模板网 All Rights Reserved 网站备案:辽ICP备19014872号-2   辽公网安备 21010602000376号  辽公网安备:42900402000182号

免责声明:本站部分资源来自互联网收集,版权归原创者所有,如果侵犯了你的权益,我们会及时删除侵权内容,联系QQ:1615187561 谢谢合作!