码迷,mamicode.com
首页 > 其他好文 > 详细

简易计算器,欢迎大神指点 改进

时间:2017-03-27 22:17:22      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:ext   var   get   utf-8   nload   type   put   ntb   click   

<!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="" />&nbsp;=
<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>

简易计算器,欢迎大神指点 改进

标签:ext   var   get   utf-8   nload   type   put   ntb   click   

原文地址:http://www.cnblogs.com/rxl1003/p/6628447.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!