2022-08-04 04:30:02 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="zh">
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8" />
|
|
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
|
|
<title>生成给定范围的随机整数</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h1>生成给定范围的随机整数</h1>
|
|
|
|
<h2>作者:赵海洋</h2>
|
|
|
|
<p>例如: 生成1-10范围的随机整数</p>
|
|
|
|
<p>随机数: <span id="random"></span></p>
|
|
|
|
<button onclick="change()">换一个</button>
|
2022-12-18 07:56:32 +00:00
|
|
|
<script>
|
2022-08-04 04:30:02 +00:00
|
|
|
function randint(min = 1, max = 10) {
|
|
|
|
min = Math.ceil(min);
|
|
|
|
max = Math.floor(max);
|
|
|
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
|
|
}
|
|
|
|
|
|
|
|
function change() {
|
|
|
|
random.innerText=randint(1, 10)
|
|
|
|
}
|
|
|
|
|
|
|
|
change()
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|