网络编程
位置:首页>> 网络编程>> JavaScript>> JS简单随机数生成方法

JS简单随机数生成方法

作者:onestopweb  发布时间:2024-04-19 09:56:42 

标签:JS,随机数

本文实例讲述了JS简单随机数生成方法。分享给大家供大家参考,具体如下:


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>随机数</title>
</head>
<body>
<script type="text/javascript">
function Randnum(value){
 var s=1000;
 var d=500;
 if(value=='b'){
   document.write(s+parseInt(500*Math.random()));
 }else{
   document.write(d+parseInt(500*Math.random()));
 }
}
</script>
<script>Randnum();</script>
</body>
</html>

效果图:

JS简单随机数生成方法

希望本文所述对大家JavaScript程序设计有所帮助。

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com