计算器无法计算结果,哪里出错了?

来源:6-11 编程练习

LanceChou

2016-09-24 21:14

<!DOCTYPE html>
<html>
 <head>
  <title> 事件</title> 
  <script type="text/javascript">
   function count(){
   var a=document.getElementById("txt1").value;
   var b=document.getElementById("ttxt2").value;
   var s=document.getElementById("select").value;
   var h="";
   switch(s)
   {
        case "+":
        he=parseInt(a)+parseInt(b);
        break;
        case "-":
        he=parseInt(a)-parseInt(b);
        break;
        case "*":
        he=parseInt(a)*parseInt(b);
        break;
        default;
        he=parseInt(a)/parseInt(b);
   }
   document.getElementById("fruit").value=h;
   }
  </script>
 </head>
 <body>
 <input id="txt1"  type="text" />
 <select id="select">
    <option type="+">+</option>
    <option type="-">-</option>
    <option type="*">*</option>
    <option type="/">/</option>
 </select>
 <input id="txt2"  type="text" />
 <input  type="button" value="=" onClick="count()"/>
 <input id="fruit"  type="text" />
 </body>
</html>

写回答 关注

1回答

  • 明明爱你cy
    2016-09-24 21:17:32
    已采纳

    变量定义错误
    http://img.mukewang.com/57e67ce80001527803650349.jpg

    LanceC...

    非常感谢!

    2016-09-24 21:21:08

    共 1 条回复 >

JavaScript进阶篇

本课程从如何插入JS代码开始,带您进入网页动态交互世界

467393 学习 · 21877 问题

查看课程

相似问题