本文提供一段完整的HTML与JavaScript代码,演示如何生成100000到999999之间的随机整数,并通过setInterval定时器每100毫秒更新页面显示。代码包含基础CSS样式与核心JS逻辑,适合初学者参考学习。
随机数生成效果展示
首先展示本次示例的运行效果。

核心代码实现
建议读者根据实际需求灵活调整,以下是具体的JavaScript实现代码。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<style>
#count{
font-size: 20px;
color: green;
width: 400px;
height: 30px;
border: 1px solid black;
margin: auto;
line-height: 30px;
text-align: center;
}
</style>
</head>
<body>
<div id="count"></div>
<script>
//产生随机数
function count (){
var i=Math.random()*(999999-100000)+100000;
var j=parseInt(i,10);
j="100000-999999随机产生:"+j;
document.getElementById("count").innerHTML= j;
}
setInterval("count()",100);
</script>
</body>
</html>
互动与优化建议
如果您有更简洁的实现方案,欢迎在评论区交流讨论。