您的位置:首页 > Web前端 > JavaScript

JS和HTML5结合做一个简单的网页计算器

2017-03-28 10:34 573 查看
<!doctype html>

<html>

  <head>

    <meta http-equiv="content-type" content="text/html;charset=gbk"/>
<title>简单计算器</title>

  </head>

  <body>

    <input type="text" id="txt1"/>
<select id="select">
  <option value="+">+</option>
  <option value="-">-</option>
  <option value="*">*</option>
  <option value="/">/</option>
</select>
<input type="text" id="txt2"/>
<input type="button" value="=" onclick="count()"/>
<input type="text" id="result"/>
<script type="text/javascript">
 function count()
 {
   var txt1=parseInt(document.getElementById("txt1").value);
var txt2=parseInt(document.getElementById("txt2").value);
var select=document.getElementById("select").value;
var result="";
switch(select)
{
 case "+":result=txt1+txt2;break;
 case "-":result=txt1-txt2;break;
 case "*":reault=txt1*txt2;break;
 case "/":reault=txt1/txt2;break;
}
document.getElementById("result").value=result;
 }
</script>

  </body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  html5 javascript