问答详情
源自:6-11 编程练习

检查不出,哪里出问题了??

<!DOCTYPE html>

<html>

 <head>

  <title> 事件</title>  

  <script type="text/javascript">

   function count(){

    var otext1 = document.getElementById("text1").value;

    var otext2 = document.getElementById("text2").value;

    var oselect = document.getElementById("select").value;

    var result ="";

    switch(oselect){

      case"+": 

          result = parseFloat(otext1) + parseFloat(otext2);

      break;

      case"-": 

          result = parseFloat(otext1) - parseFloat(otext2);

      break;

      case"*": 

          result = parseFloat(otext1) * parseFloat(otext2);

      break;

      default:

      result= parseFloat(otext1) / parseFloat(otext2);

    }

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

   }

    

    //获取第一个输入框的值

    //获取第二个输入框的值

//获取选择框的值

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

    //设置结果输入框的值 

    

   

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


提问者:修仙不如狗带 2016-05-14 17:29

个回答

  • YXP丶
    2016-05-14 18:00:45
    已采纳

    parseFloat换成parseInt

  • qq_那个猫_0
    2016-05-22 14:54:43

    你的Id错了  

    var otext1 = document.getElementById("text1").value;

        var otext2 = document.getElementById("text2").value;

        var oselect = document.getElementById("select").value;

    <input type='text' id='txt1' /> 

    都不一样

  • 违丶心
    2016-05-14 20:23:06

    id不对应

  • weibo_晓丹丹丹丹丹丹丹丹_03251526
    2016-05-14 18:09:42

    是不是和单引号双引号有关系??