首页 > 代码库 > 年会抽奖
年会抽奖
年会抽奖
小游戏,年会抽奖,都很期待的。
<body>
<div id="button">
<input id="B1" onclick="Begin()" name="B1" type="button" value="http://www.mamicode.com/开始" />
<input id="B2" onclick="Stop()" name="B2" type="button" value="http://www.mamicode.com/暂停" />
</div>
<p id="content">请准备</p>
<script type="text/javascript">
var array = new Array("王", "崔", "张", "吴", "张1", "阮", "郭", "刘", "李", "徐", "王1", "李", "东邪", "西毒", "南帝", "北丐", "思过崖", "听雨轩", "泰山顶", "六脉神剑", "七十二路剑法"); /*定义一个数组存放名字*/
var num = array.length - 1; /*从最后一个名字开始往回输出*/
var a = 1; /*标记*/
function Begin() { /*开始按钮*/
var B1 = document.getElementById("B1");
var B2 = document.getElementById("B2");
B1.disabled = true;
B2.disabled = false;
if (a == 2) { /*当a从clearTimeout(repeat);返回时就调用remove函数删除名字*/
array = remove(num, array);
}
if (num == -1) { /*走到最前面是再从后面开始走*/
num = array.length - 1;
}
document.getElementById(‘content‘).firstChild.nodeValue = http://www.mamicode.com/array[num]; /*用数组的内容代替p里面的内容*/
num--;
a = 1;
repeat = setTimeout(Begin, 40);
}
function Stop() { /*暂停按钮*/
var B1 = document.getElementById("B1");
var B2 = document.getElementById("B2");
B1.disabled = false;
B2.disabled = true;
clearTimeout(repeat); /*停止替换名字*/
a = 2; /*标记改为2*/
}
function remove(index, array) { /*删除名字函数*/
if (index >= -1 && index < array.length) {
for (var i = index + 1; i < array.length; i++) {
array[i] = array[i + 1];
}
array.length = array.length - 1;
}
return array;
}
</script>
</body>
随机抽奖的,详情可见附件文件夹。
下载地址:http://files.cnblogs.com/files/leshao/%E5%B9%B4%E4%BC%9A%E6%8A%BD%E5%A5%96.rar
年会抽奖