用html写一个简洁随机点名系统
时间: 2023-04-06 17:03:56 浏览: 85
好的,我可以回答这个问题。以下是一个简洁的随机点名系统的HTML代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>随机点名系统</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>随机点名系统</h1>
<p>点击下面的按钮,随机选择一个名字。</p>
<button onclick="randomName()">点名</button>
<p id="name"></p>
<script>
function randomName() {
var names = ["张三", "李四", "王五", "赵六", "钱七"];
var randomIndex = Math.floor(Math.random() * names.length);
document.getElementById("name").innerHTML = names[randomIndex];
}
</script>
</body>
</html>
```
这个随机点名系统包含一个按钮和一个段落,点击按钮会随机选择一个名字并在段落中显示。JavaScript代码使用了Math.random()函数和数组来实现随机选择名字的功能。
相关问题
用html写一个随机点名系统
好的,我可以回答这个问题。以下是一个简单的用HTML实现的随机点名系统:
```html
<!DOCTYPE html>
<html>
<head>
<title>随机点名系统</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1>随机点名系统</h1>
<p>点击下面的按钮,随机选择一个名字。</p>
<button onclick="randomName()">点名</button>
<p id="name"></p>
<script>
function randomName() {
var names = ["张三", "李四", "王五", "赵六", "钱七"];
var index = Math.floor(Math.random() * names.length);
document.getElementById("name").innerHTML = names[index];
}
</script>
</body>
</html>
```
这个系统包含一个按钮和一个段落,点击按钮会随机选择一个名字,并在段落中显示出来。在JavaScript代码中,我们定义了一个名字数组,然后使用Math.random()函数生成一个0到1之间的随机数,将其乘以名字数组的长度,再使用Math.floor()函数向下取整,得到一个随机的数组下标,最后将对应的名字显示在段落中。
用html写一个炫酷的随机点名系统
好的,我可以回答这个问题。以下是一个简单的用 HTML 和 JavaScript 实现的随机点名系统:
```html
<!DOCTYPE html>
<html>
<head>
<title>随机点名系统</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
}
h1 {
font-size: 2em;
margin-top: 2em;
}
button {
font-size: 1.2em;
padding: 0.5em 1em;
margin-top: 1em;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>随机点名系统</h1>
<p>点击下面的按钮随机选择一个名字:</p>
<p id="name"></p>
<button onclick="randomName()">点名</button>
<script>
var names = ["张三", "李四", "王五", "赵六", "钱七", "孙八", "周九", "吴十"];
function randomName() {
var index = Math.floor(Math.random() * names.length);
document.getElementById("name").innerHTML = names[index];
}
</script>
</body>
</html>
```
这个系统包含一个按钮和一个用于显示随机名字的段落。当用户点击按钮时,JavaScript 代码会从一个预定义的名字数组中随机选择一个名字,并将其显示在段落中。
相关推荐
![html](https://img-home.csdnimg.cn/images/20210720083451.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)