求大神帮忙看看,为什么显示不了结果

来源:6-11 编程练习

慕粉3537498

2016-12-15 22:59

<!DOCTYPE html>
<html>
 <head>
  <title> 事件</title>  
  <script type="text/javascript">
   function count(){
       var txt1=parselnt(document.getElementById('txt1').value);
       var txt2=parselnt(document.getElementById('txt2').value);
 
    var select = document.getElementById("select").value;
     var result;
     switch(select){
         case'+':
             result = txt1+txt2;
             break;
             case '-':
                 result = txt1-txt2;
                 break;
             case '*':
                 result = txt1*txt2;
                 break;
                 case'/':
                     result=txt1/txt2;
                     break;
     }
     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>

写回答 关注

2回答

  • 永晨
    2016-12-16 01:19:39
    已采纳

    哈哈,事实上楼主写的是parselnt,注意是parseInt,方法名如果你打正确了,是会变色的,注意观察。

    这种问题建议用alert();打印值排查,没有debug确实不好找。

    慕粉3537...

    非常感谢!

    2016-12-16 08:55:38

    共 1 条回复 >

  • cgf876
    2016-12-16 00:29:39

    把parseInt  中的i改成大写就行了

    慕粉3537...

    谢谢啦

    2016-12-16 21:38:36

    共 1 条回复 >

JavaScript进阶篇

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

467382 学习 · 21877 问题

查看课程

相似问题