<!DOCTYPE html>
<html>
<head>
<title>抽奖</title>
<meta charset="utf-8">
<script type="text/javascript" src="jquery-2.1.1.min.js"></script>
</head>
<body style="margin:0">
<div style="width: 600px ;height: 200px;margin: 20px auto;background-color: #f2f2f2;">
<img src="1.jpg" style="width: 180px;height: 180px;margin: 10px" id="picC">
<h1 style="float: right" id="stunum">1</h1>
<h1 style="float: right" id="stuname">孙仲仲</h1>
</div>
<div style="width: 100px;height: 30px;background-color: #f2f2f2;margin: 20px auto">
<input type="button" name="" value="开始抽奖" style="width: 100px;height: 30px" onclick="ck(this);">
</div>
<script type="text/javascript">
var arr = [
{"name":"关羽","num":"10","pic":"tm/19.1.jpg"},
{"name":"张飞","num":"9","pic":"tm/19.2.jpg"},
{"name":"赵云","num":"8","pic":"tm/19.3.jpg"},
{"name":"刘备","num":"7","pic":"tm/19.4.jpg"},
{"name":"曹操","num":"6","pic":"tm/19.5.jpg"},
{"name":"曹丕","num":"5","pic":"tm/19.6.jpg"},
{"name":"曹植","num":"4","pic":"tm/19.7.jpg"},
{"name":"曹昂","num":"3","pic":"tm/19.8.jpg"},
{"name":"曹洪","num":"2","pic":"tm/19.9.jpg"},
{"name":"孙仲仲","num":"1","pic":"tm/19.10.jpg"},
{"name":"恭喜你,中奖了!","num":"牛逼","pic":"1.jpg"},
];
//点击事件,点击切换开始和停止
var random;
function ck(obj){
if(obj.value == "开始抽奖"){
obj.value = "停止抽奖";
random = setInterval(randomNum,100);
}else{
obj.value ="开始抽奖";
clearInterval(random);
//speak(document.getElementById('stuname').innerHTML+document.getElementById('stunum').innerHTML);
}
}
//随机数函数
function randomNum(){
var n = Math.floor(Math.random() * (arr.length));
document.getElementById('picC').src = arr[n].pic;
document.getElementById('stunum').innerHTML = arr[n].num;
document.getElementById('stuname').innerHTML = arr[n].name;
}
//语音播报
//var synth = window.speechSynthesis;
//var u = new SpeechSynthesisUtterance();
//u.lang = 'zh-CN';//汉语
//u.rate = 1;
//function speak(textToSpeak) {
//u.text = textToSpeak;
//synth.speak(u);
//}
</script>
</body>
</html>
抽奖
最新推荐文章于 2025-05-08 00:16:39 发布