码迷,mamicode.com
首页 > Web开发 > 详细

web 一个简易的计算器

时间:2016-08-14 07:11:38      阅读:755      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!