js实现随机数抽奖

本文介绍了如何使用JavaScript编写一个随机数抽奖程序。通过源代码展示,解释了关键的算法和逻辑,帮助读者理解如何在网页中实现抽奖效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

;;;;;;;;;;;;;;源码::::::::::

<!DOCTYPE html>

<html lang="zh">
<head>
<title>幸运抽奖</title>
<script type="text/javascript">
var randNum=Math.random()*100;
function testTime(){
document.getElementById("testtime").innerHTML="<h2>"+Math.floor(Math.random()*100)+"</h2>";
}
    
function setTime(mark){
timer=null;
timer=setInterval(testTime,60);
if(mark=='stop'){
    clearInterval(timer);
}
return timer;
}
function clearTime(timer){ }
</script>
<style type="text/css">
<!--
body {font-family: Arial;color:rgb(91, 100, 230);margin: 0px;padding: 50px;background:rgb(245, 201, 209);text-align:center;}
#happyness{font-size:186px;line-height:186px;margin-top:100px;}
-->
</style>
</head>
<body>
</body>
<button onClick="timer=setInterval(testTime,60);" value="" style="width:100px;height:30px">开始</button>&nbsp;  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;      
<button onClick="clearInterval(timer);" value="Stop" style="width:100px;height:30px">停止</button>
<div id="testtime" style="font-size:180px"></div>
<br>

</html>


:::::::::::::::::效果::::::::::::::::::::::::



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值