大家在制作网页或者小程序的时候经常用到随机数,作者整理了一个很简单的JS生成随机数的程序,一起学习下。
我们先来看下本次源码的效果图

大家可以灵活运用,我们把具体JS代码分享给大家:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <!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>
<p id= "count" ></p>
<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>
|
登录后复制
上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:
如何使用ngrok+express解决微信接口调试问题
如何使用vue-cli编写vue插件
在element ui里如何使dialog关闭后清除验证
以上是在JS中如何生成随机数(详细教程)的详细内容。更多信息请关注PHP中文网其他相关文章!