您的位置:首页 > 其它

三种简单又快捷的方法让你弄懂随机数

2017-08-18 16:06 134 查看
<!DOCTYPE html>

<html lang="en">

<head>
<meta charset="UTF-8">
<title>随机数</title>

</head>

<body>

    <!-- 第一种方法 -->
<script>
  document.write("第一种方法:"+"<br/>");
  document.write("您的随机数为:");
  document.write(Math.floor(Math.random(1)*39+1)+"<br/>"+"<br/>");
 
</script>

   <!-- 第二种方法 -->

     <input type="button" value="请您抽取随机数" onclick="document.getElementById('random').value=Math.floor(Math.random(1)*40)" /> 

     <input type="text" value="" id="random" />

     <br/><br/>

 <!-- 第二种方法 -->
<input type="button" id="a" value="猜猜幸运儿是谁" onclick="butt()"/>
<script>
   function butt(){
       document.getElementById('a').value=Math.floor(Math.random(1)*(40));
   }
</script>

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: