三种简单又快捷的方法让你弄懂随机数
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>
<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>
相关文章推荐
- 三种方法教你快速查看CAD图纸,简单方便快捷
- Android studio引入so文件的方法,最简单快捷的方法!
- 素数判断的三种方法以及简单实现!
- 浅谈iOS中三种生成随机数方法
- 三种在 Linux 上创建或扩展交换分区的简单方法
- ios中三种随机数方法
- Python简单生成随机数的方法示例
- ios 有如下三种随机数方法
- 简单快捷PHP数组赋值方法详解
- ubuntu12.4创建桌面快捷方式(三种方法)
- 三种方法编写的简单html界面(2)
- php生成随机数的三种方法
- cocos2d-x 2.x使用python脚本快捷创建项目的简单方法
- Java并发29:ThreadLocalRandom学习笔记-随机数的三种使用方法
- 三种简单的html网页自动跳转方法
- ubuntu QT开发环境(三种方法安装Qt4.8,其中apt-get方法安装QT库最简单)good
- 三种在 Linux 上创建或扩展交换分区的简单方法
- php简单生成随机数的方法
- java简单实现缓存的三种方法
- 查询ip地址的三种简单的方法