写一个随机生成1到100的html代码
时间: 2024-06-06 09:07:48 浏览: 5
<!DOCTYPE html>
<html>
<head>
<title>随机生成1到100的数</title>
<script type="text/javascript">
function generateRandomNumber() {
var randomNumber = Math.floor(Math.random() * 100) + 1;
document.getElementById("random-number").innerHTML = randomNumber;
}
</script>
</head>
<body>
<h1>随机生成1到100的数:</h1>
<button onclick="generateRandomNumber()">点击生成</button>
<p id="random-number"></p>
</body>
</html>
相关问题
写一个Html代码随机生成数字可添加范围以及符号
好的,以下是一个可以在 HTML 中随机生成数字并添加范围和符号的示例代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>随机生成数字</title>
<meta charset="UTF-8">
<script type="text/javascript">
function generateRandomNumber() {
var min = parseInt(document.getElementById("min").value);
var max = parseInt(document.getElementById("max").value);
var symbol = document.getElementById("symbol").value;
var randomNumber = Math.floor(Math.random() * (max - min + 1)) + min;
document.getElementById("result").innerHTML = symbol + randomNumber + symbol;
}
</script>
</head>
<body>
<label for="min">最小值:</label>
<input type="number" id="min" value="0"><br>
<label for="max">最大值:</label>
<input type="number" id="max" value="100"><br>
<label for="symbol">符号:</label>
<input type="text" id="symbol" value=""><br>
<button onclick="generateRandomNumber()">生成随机数</button>
<p id="result"></p>
</body>
</html>
```
这段代码包括一个最小值的输入框、一个最大值的输入框、一个符号的输入框和一个“生成随机数”的按钮。当用户点击按钮时,JavaScript 函数 `generateRandomNumber()` 会从最小值到最大值之间生成一个随机整数,并在结果前后添加指定的符号。最终的结果将显示在 `<p>` 元素中。
帮我写一段html代码,生成随机双色球号码
Sure, 以下是一段用HTML生成随机双色球号码的代码:
```
<!DOCTYPE html>
<html>
<body>
<h1>随机双色球号码生成器</h1>
<p>下面是您的随机双色球号码:</p>
<!-- 生成随机号码 -->
<script>
// 从1到33中选择6个不重复号码
var redBall = [];
while (redBall.length < 6) {
var redNum = Math.floor(Math.random() * 33) + 1;
if (redBall.indexOf(redNum) === -1) {
redBall.push(redNum)
}
}
// 从1到16中选择1个蓝球号码
var blueBall = Math.floor(Math.random() * 16) + 1;
// 显示生成的随机号码
document.write("<p>红球: " + redBall.sort(function(a, b){return a-b}).join(" ") + "</p>");
document.write("<p>蓝球: " + blueBall + "</p>");
</script>
</body>
</html>
```
请复制上面的代码并保存成一个HTML文件,在浏览器中运行即可生成随机双色球号码。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)