简易计算器,欢迎大神指点 改进
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了简易计算器,欢迎大神指点 改进相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
onload = function() {
document.getElementById(‘add‘).onclick = function(){
var iNum1 = document.getElementById(‘Num1‘).value;
var iNum2 = document.getElementById(‘Num2‘).value;
var iNum = parseInt(iNum1) + parseInt(iNum2);
// alert(iNum);
var onThree = document.getElementById(‘Num3‘);
onThree.value = iNum;
}
document.getElementById(‘sub‘).onclick = function(){
var iNum1 = document.getElementById(‘Num1‘).value;
var iNum2 = document.getElementById(‘Num2‘).value;
var iNum = parseInt(iNum1) - parseInt(iNum2);
// alert(iNum);
var onThree = document.getElementById(‘Num3‘);
onThree.value = iNum;
}
document.getElementById(‘mul‘).onclick = function(){
var iNum1 = document.getElementById(‘Num1‘).value;
var iNum2 = document.getElementById(‘Num2‘).value;
var iNum = parseInt(iNum1) * parseInt(iNum2);
// alert(iNum);
var onThree = document.getElementById(‘Num3‘);
onThree.value = iNum;
}
document.getElementById(‘divi‘).onclick = function(){
var iNum1 = document.getElementById(‘Num1‘).value;
var iNum2 = document.getElementById(‘Num2‘).value;
var iNum = parseInt(iNum1) / parseInt(iNum2);
// alert(parseInt(iNum));
var onThree = document.getElementById(‘Num3‘);
onThree.value = iNum;
}
}
</script>
</head>
<body>
<!--输入框-->
<input type="text" name="Num1" id="Num1" value="" />
<input type="text" name="Num2" id="Num2" value="" /> =
<input type="text" name="num1" id="Num3" value="" />
<br />
<!--运算符-->
<input type="button" name="add" id="add" value="+" />
<input type="button" name="sub" id="sub" value="-" />
<input type="button" name="mul" id="mul" value="*" />
<input type="button" name="divi" id="divi" value="/" />
</body>
</html>
以上是关于简易计算器,欢迎大神指点 改进的主要内容,如果未能解决你的问题,请参考以下文章
JS 计算两个日期之间的月份,不足一个月按一个月计算(求大神指点)