新建3-4.html文件,在<body></body>中插入JavaScript脚本,判断一个数的奇偶性,并将结果输出在页面中显示如下图。(要求先对输入内容进行判断,如不是数值则返回‘参数不正确’,再进行数值奇偶性的判断,并将结果输出。需用到return 语句。)
时间: 2024-03-21 13:44:41 浏览: 78
好的,你可以参考下面的代码实现:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>判断奇偶性</title>
</head>
<body>
<input type="text" id="num" placeholder="请输入一个整数">
<button onclick="check()">判断奇偶性</button>
<p id="result"></p>
<script>
function check() {
var num = document.getElementById("num").value;
if (isNaN(num)) {
document.getElementById("result").innerHTML = "参数不正确";
} else {
if (num % 2 == 0) {
document.getElementById("result").innerHTML = num + "是偶数";
} else {
document.getElementById("result").innerHTML = num + "是奇数";
}
}
}
</script>
</body>
</html>
```
你可以将上面的代码保存为一个名为 `3-4.html` 的文件,然后在浏览器中打开它,输入一个整数,点击“判断奇偶性”按钮即可看到判断结果。
相关问题
py,提取天猫店铺中一段信息 “<html><head><title>南美白虾仁</title></head><body>KingOscar 原装进口生冻南美白虾仁鲜活海鲜水产印度大虾仁 500g-tmall.com天猫</body></html>” 中的宝贝名称和宝贝创意
好的,以下是Python3的代码实现:
```python
import re
info = '<html><head><title>南美白虾仁</title></head><body>KingOscar 原装进口生冻南美白虾仁鲜活海鲜水产印度大虾仁 500g-tmall.com天猫</body></html>'
# 提取宝贝名称
title_pattern = re.compile(r'<title>(.*?)</title>')
title = title_pattern.search(info).group(1)
# 提取宝贝创意
body_pattern = re.compile(r'<body>(.*?)</body>')
body = body_pattern.search(info).group(1)
creativity_pattern = re.compile(r'(.+?)\d{3}g-')
creativity = creativity_pattern.search(body).group(1)
print('宝贝名称:', title)
print('宝贝创意:', creativity)
```
输出结果为:
```
宝贝名称: 南美白虾仁
宝贝创意: KingOscar 原装进口生冻南美白虾仁鲜活海鲜水产印度大虾仁
```
<!DOCTYPE html> <html> <head> <title>Bootstrap Buttons</title> <!-- 引入Bootstrap样式文件 --> <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.3/css/bootstrap.min.css"> </head> <body> <div class="container-fluid d-flex justify-content-center align-items-center" style="height: 100vh;"> <div class="row"> <div class="col-md-12"> <button class="btn btn-primary mr-3">Button 1</button> <button class="btn btn-secondary">Button 2</button> </div> </div> </div> <!-- 引入Bootstrap JavaScript文件 --> <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.3/js/bootstrap.min.js"></script> </body> </html>,如何调整Button大小与间距
可以通过调整Bootstrap按钮的样式类来改变按钮的大小和间距。首先,可以使用`btn-lg`、`btn-sm`和`btn-xs`类来设置按钮的大小,分别对应大、小和超小三种尺寸。例如,将按钮1设置为大尺寸,可以将`btn-primary`类改为`btn-primary btn-lg`。同样,将按钮2设置为超小尺寸,可以将`btn-secondary`类改为`btn-secondary btn-xs`。
其次,可以使用`mr-*`和`ml-*`类来设置按钮之间的间距。这些类可以控制按钮的右边距和左边距,其中`*`表示间距的大小。例如,将按钮1和按钮2之间的间距设置为20像素,可以为按钮1添加`mr-2`类,为按钮2添加`ml-2`类。
下面是相应的代码示例:
```html
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap Buttons</title>
<!-- 引入Bootstrap样式文件 -->
<link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.3/css/bootstrap.min.css">
</head>
<body>
<div class="container-fluid d-flex justify-content-center align-items-center" style="height: 100vh;">
<div class="row">
<div class="col-md-12">
<button class="btn btn-primary btn-lg mr-2">Button 1</button>
<button class="btn btn-secondary btn-xs ml-2">Button 2</button>
</div>
</div>
</div>
<!-- 引入Bootstrap JavaScript文件 -->
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.3/js/bootstrap.min.js"></script>
</body>
</html>
```
在上面的示例中,我们将按钮1的样式类设置为`btn-primary btn-lg mr-2`,将按钮2的样式类设置为`btn-secondary btn-xs ml-2`,从而实现了按钮的大小和间距的调整。
相关推荐
![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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)