u编程:在第1个文本框输入第一个数,在第2个文本框输入第二个数,单击运行按钮,在第3个文本框显示两数之和。运行界面如下图所示: image.png image.png
时间: 2023-06-15 09:03:02 浏览: 56
这是一个简单的网页程序,可以使用HTML、CSS和JavaScript来实现。以下是示例代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>计算器</title>
<style>
label {
display: block;
margin-bottom: 10px;
}
input[type="number"] {
width: 100%;
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
#result {
margin-top: 10px;
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
}
</style>
</head>
<body>
<h1>计算器</h1>
<form>
<label>第一个数:<input type="number" id="num1"></label>
<label>第二个数:<input type="number" id="num2"></label>
<button type="button" onclick="calculate()">运行</button>
</form>
<div id="result"></div>
<script>
function calculate() {
var num1 = parseFloat(document.getElementById("num1").value);
var num2 = parseFloat(document.getElementById("num2").value);
var result = num1 + num2;
document.getElementById("result").innerHTML = "结果:" + result;
}
</script>
</body>
</html>
```
你可以将上述代码复制到一个HTML文件中,并使用浏览器打开该文件,即可看到一个简单的计算器界面。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)