首页 > Web开发 > 详细

web 一个简易的计算器

时间:2016-08-14 07:09:08      阅读:173      评论:0      收藏:0      [点我收藏+]

<html>
<head>
<script type="text/javascript" src="1.js"></script>
</head>
<body>
<input type="text" id="num1"/><br/>
<input type="text" id="num2"/><br/>
<input type="text" id="num3"/><br/>
<input type="button" onclick="func1(‘+‘)" value=" + "/>
<input type="button" onclick="func1(‘-‘)" value=" - "/>
<input type="button" onclick="func1(‘*‘)" value=" * "/>
<input type="button" onclick="func1(‘/‘)" value=" / "/>
</body>
</html>

 


function func1(val){
var a=parseFloat(document.getElementById(‘num1‘).value);
var b=parseFloat(document.getElementById(‘num2‘).value);

if(val==‘+‘){
num3.value=a+b;
}
if(val=="-"){
num3.value=a-b;
}
if(val=="*"){
num3.value=a*b;
}
if(val=="/"){
num3.value=a/b;
}
}

 

web 一个简易的计算器

原文:http://www.cnblogs.com/yuanceo/p/5769064.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!