<!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>