yxhxj2006

          常用鏈接

          統計

          最新評論

          計算器簡單實現

          <html>
          <head>
          <script>
            var flag = true;
            function getNum(num){
              if(!flag){
              document.getElementById('res').value = '';
              flag = true;
           }
              document.getElementById('res').value += num;
            }
            function getResult(){
              var result = eval(document.getElementById('res').value);
           document.getElementById('res').value = result;
           flag = false;
            }
          </script>
          </head>
          <body>
          <table border='1px' width='300px'>
          <caption>計算器</caption>
          <tr>
           <td colspan='4'><input type='text' id='res' size=47></td>
           
          </tr>
          <tr>
           <td><input type='button' value='1' style="width:75px" onclick="getNum(1)"></td>
           <td><input type='button' value='2' style="width:75px" onclick="getNum(2)"></td>
           <td><input type='button' value='3' style="width:75px" onclick="getNum(3)"></td>
           <td><input type='button' value='+' style="width:75px" onclick="getNum('+')"></td>
          </tr>
          <tr>
           <td><input type='button' value='4' style="width:75px" onclick="getNum(4)"></td>
           <td><input type='button' value='5' style="width:75px" onclick="getNum(5)"></td>
           <td><input type='button' value='6' style="width:75px" onclick="getNum(6)"></td>
           <td><input type='button' value='-' style="width:75px" onclick="getNum('-')"></td>
          </tr>
          <tr>
           <td><input type='button' value='7' style="width:75px" onclick="getNum(7)"></td>
           <td><input type='button' value='8' style="width:75px" onclick="getNum(8)"></td>
           <td><input type='button' value='9' style="width:75px" onclick="getNum(9)"></td>
           <td><input type='button' value='*' style="width:75px" onclick="getNum('*')"></td>
          </tr>
          <tr>
           <td><input type='button' value='0' style="width:75px" onclick="getNum(0)"></td>
           <td><input type='button' value='.' style="width:75px" onclick="getNum('.')"></td>
           <td><input type='button' value='=' style="width:75px" onclick="getResult()"></td>
           <td><input type='button' value='/' style="width:75px" onclick="getNum('/')"></td>
          </tr>
          </table>
          </body>
          </html>

          posted on 2014-02-28 01:05 奮斗成就男人 閱讀(186) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 徐闻县| 眉山市| 西昌市| 合江县| 阜康市| 海门市| 化隆| 淄博市| 保德县| 湖北省| 景洪市| 镇安县| 白水县| 阿瓦提县| 库尔勒市| 神木县| 色达县| 古丈县| 嘉禾县| 青川县| 桃源县| 古田县| 东宁县| 香河县| 融水| 儋州市| 临邑县| 延寿县| 阳西县| 霍城县| 蓬莱市| 昂仁县| 山东省| 扶风县| 定兴县| 启东市| 茌平县| 宜都市| 麻栗坡县| 开鲁县| 天镇县|