level 1
jbweb2006
楼主
<!DOCTYPE html>
<html>
<head>
<title>简易计算器</title>
<meta charset="gb2312">
<style type="text/css">
#num1 { border: 1px solid red;}
#fh { border: 1px solid #ff00ff;}
#num2 { border: 1px solid green;}
#result { border: 1px solid blue;}
#btn1 { background: black; color:white;}
</style>
<script type="text/javascript">
function show()
{
var num1 = document.getElementById("num1").value;
var num2 = document.getElementById("num2").value;
var fh = document.getElementById("fh").value;
num1 = parseFloat(num1);
num2 = parseFloat(num2);
switch(fh)
{
case "+":
res = num1+num2;
break;
case "-":
res = num1-num2;
break;
case "*":
res = num1*num2;
break;
case "/":
res = num1/num2;
break;
default:
break;
}
document.getElementById("result").value = res;
}
</script>
</head>
<body>
第一个数:<input type="text" id="num1">
<br><br>
运算符号:
<select id="fh">
<option value="+">加</option>
<option value="-">减</option>
<option value="*">乘</option>
<option value="/">除</option>
</select>
<br><br>
第二个数:<input type="text" id="num2">
<br><br>
<input type="button" value="运算" onclick="show()" id="btn1">
<br><br>
结果:<input type="text" id="result">
</body>
</html>
2019年07月26日 14点07分
1
<html>
<head>
<title>简易计算器</title>
<meta charset="gb2312">
<style type="text/css">
#num1 { border: 1px solid red;}
#fh { border: 1px solid #ff00ff;}
#num2 { border: 1px solid green;}
#result { border: 1px solid blue;}
#btn1 { background: black; color:white;}
</style>
<script type="text/javascript">
function show()
{
var num1 = document.getElementById("num1").value;
var num2 = document.getElementById("num2").value;
var fh = document.getElementById("fh").value;
num1 = parseFloat(num1);
num2 = parseFloat(num2);
switch(fh)
{
case "+":
res = num1+num2;
break;
case "-":
res = num1-num2;
break;
case "*":
res = num1*num2;
break;
case "/":
res = num1/num2;
break;
default:
break;
}
document.getElementById("result").value = res;
}
</script>
</head>
<body>
第一个数:<input type="text" id="num1">
<br><br>
运算符号:
<select id="fh">
<option value="+">加</option>
<option value="-">减</option>
<option value="*">乘</option>
<option value="/">除</option>
</select>
<br><br>
第二个数:<input type="text" id="num2">
<br><br>
<input type="button" value="运算" onclick="show()" id="btn1">
<br><br>
结果:<input type="text" id="result">
</body>
</html>