哪里出错了,为什么的不出来结果呢?

来源:6-11 编程练习

妖小喵_

2018-03-19 15:08

<!DOCTYPE html>

<html>

 <head>

  <title> 事件</title>  

  <script type="text/javascript">

   function count(){

   var d="";

   var text1=parseInt(document.getElementById("text1").value);//获取第一个输入框的值

   var text2=parseInt(document.getElementById("text2").value);//获取第二个输入框的值

   var select=parseInt(document.getElementById("select").value);//获取选择框的值

    switch(select){

        case '+':

        d = text1 + text2;

     break;

     

     case '-':

        d = text1 - text2;

     break;

     

     case '*':

        d = text1 * text2;

     break;

     

     case '/':

        d = text1 / text2;

     break;

    }

document.getElementById("fruit").value = d;

//获取通过下拉框来选择的值来改变加减乘除的运算法则

    //设置结果输入框的值 

   }

  </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回答

  • alfei13
    2018-03-21 10:21:03

    e , 不好意思, 答错人了,

    你这个问题有3

    1. var text1,text2,select, 后面标点错了;

    2. text1,text2,的对应的id错了;

    3. select变量赋值时候不应该用parseInt();

  • alfei13
    2018-03-19 19:32:47

    http://img1.mukewang.com/5aaf9fd100012da106380186.jpg你的标点写错了

    alfei1... 回复妖小喵_

    e , 不好意思, 答错人了, 你这个问题有3 var text1,text2,select, 后面标点错了; text1,text2,的对应的id错了; select变量赋值时候不应该用parseInt();

    2018-03-21 10:21:25

    共 2 条回复 >

  • 若离殇
    2018-03-19 17:18:28

    case "*":;  分号去掉

JavaScript进阶篇

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

467395 学习 · 21877 问题

查看课程

相似问题