首页 > 代码库 > 简易计算器,欢迎大神指点 改进
简易计算器,欢迎大神指点 改进
<!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 = http://www.mamicode.com/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 = http://www.mamicode.com/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 = http://www.mamicode.com/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 = http://www.mamicode.com/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="http://www.mamicode.com/+" />
<input type="button" name="sub" id="sub" value="http://www.mamicode.com/-" />
<input type="button" name="mul" id="mul" value="http://www.mamicode.com/*" />
<input type="button" name="divi" id="divi" value="http://www.mamicode.com/" />
</body>
</html>
简易计算器,欢迎大神指点 改进