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

计算器

时间:2016-05-08 20:00:01      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html> <html> <head lang="en">     <meta charset="UTF-8">     <!--<meta http-equiv="content-type" content="text/html"; charset="GB2312"/>-->     <title></title>     <style>         input {             border: solid 1px black         }
.cc { width: 18px } </style> </head> <body> <input type="text" id="num1"/> <input type="text" id="mum3" class="cc"/> <input type="text" id="num2"/> <input type="button" value="等于" id="btnCal"/> <input type="text" id="num3"/> </body> <script type="text/javascript"> function calSum(){ var a=parseInt(document.getElementById("num1").value); var b=parseInt(document.getElementById("num2").value); var c=String(document.getElementById("mum3").value); // switch(c){ // case"+":document.getElementById("num3").value =(a+b);break; // case"-":document.getElementById("num3").value =(a-b);break; // case"*":document.getElementById("num3").value =(a*b);break; // case"/":document.getElementById("num3").value =(a/b);break; // case"%":document.getElementById("num3").value =(a%b);break; // } if (c==="+") { document.getElementById("num3").value = (a + b); } else { if (c==="-") { document.getElementById("num3").value = (a - b); } else { document.getElementById("num3").value = (a / b); if (c==="*") { document.getElementById("num3").value = (a * b); } else { document.getElementById("num3").value = (a / b); } } }

}
//function calSum(){ // var a=parseInt(document.getElementById("num1").value); // var b=parseInt(document.getElementById("num2").value); // var c=String(document.getElementById("mum3").value); // switch (c){ // case "+":document.getElementById("num3").value= (a+b);break; // case "-":document.getElementById("num3").value=(a-b);break; // case "*":document.getElementById("num3").value=(a*b);break; // case "/":document.getElementById("num3").value= (a/b);break; // case "%" :document.getElementById("num3").value= (a%b);break; // } //} document.getElementById("btnCal").onclick=calSum; </script>
</html>

计算器

标签:

原文地址:http://www.cnblogs.com/dugufeiyang/p/5471219.html

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