<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>随机数</title>
</head>
<body>
<h2>生成随机数</h2>
<p>【-20 与 20 之间的随机数】</p>
<p id="demo"></p>
<button onclick="randomNumber(-20,20)">点击</button>
<script>
function randomNumber(min, max) {
document.getElementById('demo').innerHTML =
Math.floor(Math.random() * (max - min + 1)) + min
}
</script>
</body>
</html>
还挺有趣的。。。