用asp.net语言写简易计算器
时间: 2023-03-31 22:03:05 浏览: 186
用asp.net编写的一个简单计算器
4星 · 用户满意度95%
可以使用以下代码来实现一个简易计算器:
<%@ Page Language="C#" %>
<!DOCTYPE html>
<html>
<head>
<title>简易计算器</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<label for="num1">第一个数字:</label>
<input type="text" id="num1" name="num1" />
</div>
<div>
<label for="num2">第二个数字:</label>
<input type="text" id="num2" name="num2" />
</div>
<div>
<label for="operator">运算符:</label>
<select id="operator" name="operator">
<option value="+">加</option>
<option value="-">减</option>
<option value="*">乘</option>
<option value="/">除</option>
</select>
</div>
<div>
<input type="button" value="计算" onclick="calculate()" />
</div>
<div>
<label for="result">结果:</label>
<input type="text" id="result" name="result" readonly="readonly" />
</div>
</form>
<script type="text/javascript">
function calculate() {
var num1 = parseFloat(document.getElementById("num1").value);
var num2 = parseFloat(document.getElementById("num2").value);
var operator = document.getElementById("operator").value;
var result;
switch (operator) {
case "+":
result = num1 + num2;
break;
case "-":
result = num1 - num2;
break;
case "*":
result = num1 * num2;
break;
case "/":
result = num1 / num2;
break;
}
document.getElementById("result").value = result;
}
</script>
</body>
</html>
阅读全文