js製作簡單的計算機

來源:互聯網
上載者:User

標籤:

學著做了一個簡單的計算機!記錄記錄!哈哈

<!DOCTYPE html>

<html>

<head>

          <title>簡單的計算機</title>  

          <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

        <style type="text/css">

              input{width:100%}

      </style>

</head>

<body> 

     <script type="text/javascript">

      function compute(obj)

      {   

       obj.expr.value=eval(obj.expr.value)

      }    

     var plus="+";  

  var minus="-";  

  var multiply="*";

  var divide="/";  

 var decimal=".";

   function enter(obj,string)

 {   

      obj.expr.value+=string;  

}  

function cle(obj)

      {      

   obj.expr.value=‘‘; 

      }  

     </script>

<form >  

<table border=1>

<tr >    

<td colspan="4"><input type="text" name="expr" size="30"  style="width:97%"></td>  

</tr>   

<tr>    

<td><input type="button" value="7" onclick="enter(this.form,7)"></td>      

<td><input type="button" value="8" onclick="enter(this.form,8)"></td>      

<td><input type="button" value="9" onclick="enter(this.form,9)"></td>      

<td><input type="button" value="/" onclick="enter(this.form,divide)"></td>  

</tr>   

<tr>    

<td><input type="button" value="4" onclick="enter(this.form,4)"></td>    

<td><input type="button" value="5" onclick="enter(this.form,5)"></td>   

<td><input type="button" value="6" onclick="enter(this.form,6)"></td>  

<td><input type="button" value="*" onclick="enter(this.form,multiply)"</td>  

</tr>  

<tr>      

<td><input type="button" value="1" onclick="enter(this.form,1)"></td>    

<td><input type="button" value="2" onclick="enter(this.form,2)"></td>      

<td><input type="button" value="3" onclick="enter(this.form,3)"></td>     

<td><input type="button" value="-" onclick="enter(this.form,minus)"></td>   

</tr>

<tr>   

<td colspan="2"><input type="button" value="0" onclick="enter(this.form,0)"></td>

<td><input type="button" value="." onclick="enter(this.form,decimal)"></td>  

<td><input type="button" value="+" onclick="enter(this.form,plus)"></td>  

</tr>      

<tr>     

      <td colspan="2" ><input type="button" value="=" onclick="compute(this.form)" ></td>    

<td colspan="2"><input type="button" value="AC" size=3 onclick="cle(this.form)"></td>      

</tr>

</table>

</form>

</body>

</html>

js製作簡單的計算機

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.