为了账号安全,请及时绑定邮箱和手机立即绑定

6-11输出不了结果

6-11输出不了结果

goasleep 2016-02-19 22:22:38
<!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>
查看完整描述

1 回答

?
李晓健

TA贡献1036条经验 获得超461个赞

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

这两个的id写的和下面html中的不对应

查看完整回答
反对 回复 2016-02-20
  • 1 回答
  • 0 关注
  • 1493 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信