各位大神能帮我找下错误吗?还是无法运行

来源:6-11 编程练习

慕数据4568312

2018-10-29 12:38

<!DOCTYPE html>
<html>
 <head>
  <title> 事件</title>  
  <script type="text/javascript">
   function count(){
       
    //获取第一个输入框的值
    var shu1 = parseInt(document.getElementById('txt1').value);
    
    //获取第二个输入框的值
    var shu2 = parseInt(document.getElementById('txt2').value);
    
    //获取选择框的值
    var fu = document.getElementById('select').value;
    
    //获取通过下拉框来选择的值来改变加减乘除的运算法则
    var final ='';
    swich (fu){
        
       case '+' :
       fianl = shu1 + shu2;
       break;
       case '-' :
        final = shu1 - shu2;
        break;
        case '*' :
        fianl = shu1 * shu2;
        break;
        case '/' :
       final = shu1 / shu2;
       break;
    }
    
    
    //设置结果输入框的值
    document.getElementById("fruit").value = final;
    
   }
  </script>
 </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='fruit' />   
 </body>
</html>

写回答 关注

3回答

  • Micheal_Gao
    2018-11-01 17:01:33
    已采纳

    https://img.mukewang.com/5bdac08d00014cad05880705.jpg

    这3个位置拼写错误,switch , final , final。。

    这种拼写错误一定要注意啊,找错的话请用本地浏览器来查,很容易发现的

    慕数据456...

    谢谢您

    2018-11-02 08:47:50

    共 1 条回复 >

  • 凝木雨
    2018-10-30 11:37:02

    var final =''
    这里拼错了,应该是
    var final=""
    英文的双引号少了一半

  • 慕斯卡2328912
    2018-10-29 17:10:20

    switch 函数里面 + 和* 变量名错了

    慕数据456...

    不是诶,我改了,然后还是无法输出

    2018-10-31 14:08:36

    共 1 条回复 >

JavaScript进阶篇

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

467402 学习 · 21877 问题

查看课程

相似问题