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)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 汾阳市| 澎湖县| 梅州市| 灵丘县| 津南区| 麻城市| 富民县| 巴青县| 山阴县| 新河县| 红原县| 石棉县| 江达县| 蒲江县| 恩平市| 南平市| 巴彦淖尔市| 富宁县| 阳谷县| 鄱阳县| 吴桥县| 松滋市| 乳源| 巴东县| 虹口区| 聂荣县| 仙居县| 泾源县| 白山市| 丹棱县| 新竹市| 明水县| 高密市| 梓潼县| 尖扎县| 武安市| 彰武县| 阳曲县| 四子王旗| 吉安市| 丹江口市|