随机抽奖
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="text/javascript" src="jquery.js"></script>
<script language='javascript' type='text/javascript'>
var imgs = ["pic/1.jpg",
"pic/2.jpg",
"pic/3.jpg",
];
var startId;
var index;
$(function () {
$("#startID").prop("disabled",false);
$("#stopID").prop("disabled",true);
$("#startID").click(function () {
startId = setInterval(function () {
$("#startID").prop("disabled",true);
$("#stopID").prop("disabled",false);
index = Math.floor(Math.random() * 3);
$("#img1ID").prop("src",imgs[index]);
},20);
});
$("#stopID").click(function () {
$("#startID").prop("disabled",false);
$("#stopID").prop("disabled",true);
clearInterval(startId);
$("#img2ID").prop("src",imgs[index]).hide();
$("#img2ID").show(1000);
});
});
</script>
</head>
<body>
<div style="border-style:dotted;width:160px;height:100px">
<img id="img1ID" src="pic/1.gif" style="width:160px;height:100px"/>
</div>
<div
style="border-style:double;width:800px;height:500px;position:absolute;left:500px;top:10px">
<img id="img2ID" src="pic/1.gif" width="800px" height="500px"/>
</div>
<input
id="startID"
type="button"
value="点击开始"
style="width:150px;height:150px;font-size:22px">
<input
id="stopID"
type="button"
value="点击停止"
style="width:150px;height:150px;font-size:22px">
</body>
</html>