6-11输出不了结果

<!DOCTYPE html>

<html>

 <head>

  <title> 事件</title>  

  <script type="text/javascript">

   function count(){

       

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

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

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

    var re;

switch(f)

    {

        case "+":

            re=parseInt(count1)+parseInt(count2);

            break;

        case "-":

            re=parseInt(count1)-parseInt(count2);

            break;

        case "*":

            re=parseInt(count1)*parseInt(count2);

            break;

        case "/":

            re=parseInt(count1)/parseInt(count2);

            break;

    }

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

    

   }

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


goasleep
浏览 1494回答 1
1回答

李晓健

var count1=document.getElementById("txt1").value;//获取第一个输入框的值 var count2=document.getElementById("txt2").value;  //获取第二个输入框的值这两个的id写的和下面html中的不对应
打开App,查看更多内容
随时随地看视频慕课网APP