js实现极为简单的计算器
程序员文章站
2022-03-06 13:10:53
...
超简便的计算器
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>calculator</title>
</head>
<body>
<div>
<span>第一个数</span>
<input type="" name="" id="number1" value="" />
<br>
<span>第二个数</span>
<input type="" name="" id="number2" value="" />
<br>
<input type="submit" value="+" onclick="add()">
<input type="submit" value="-" onclick="delect()">
<input type="submit" value="*" onclick="mul()">
<input type="submit" value="/" onclick="divi()">
<div id="">
<span>计算结果:</span><span id="result"></span>
</div>
</div>
<script type="text/javascript">
//加法
function add() {
add1 = Number(document.getElementById("number1").value);
add2 = Number(document.getElementById("number2").value);
var sum;
sum = add1 + add2;
document.getElementById("result").innerHTML = sum;
}
//减法
function delect() {
add1 = Number(document.getElementById("number1").value);
add2 = Number(document.getElementById("number2").value);
var sum;
sum = add1 - add2;
document.getElementById("result").innerHTML = sum;
}
//乘法
function mul() {
add1 = Number(document.getElementById("number1").value);
add2 = Number(document.getElementById("number2").value);
var sum;
sum = add1 * add2;
document.getElementById("result").innerHTML = sum;
}
//除法
function divi() {
add1 = Number(document.getElementById("number1").value);
add2 = Number(document.getElementById("number2").value);
var sum;
sum = add1 / add2;
document.getElementById("result").innerHTML = sum;
}
</script>
</body>
</html>
上一篇: 如何画线条?手绘人物线条教学!
下一篇: Django的安装及配置环境变量