This method is super simple, the idea is very worthy of recommendation, small partners to refer to the next bar
Copy Code code as follows:
<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title>javascript Simple Calculator </title>
<script>
Define global variable var one= "1";
var two= "2";
var three= "3";
var four= "4";
var five= "5";
var six= "6";
var seven= "7";
var eight= "8";
var nine= "9";
var zero= "0";
var plus= "+", minus= "-", multiply= "*", divide= "/", decimal= ".";
function Enter (obj,string) {
obj.expr.value+=string;
}
function Compute (obj) {//Click functions equal to the ' = ' button; Obj.expr.value=eval (Obj.expr.value);///Use the JS eval () method to compute the formula named expr in
</script>
<body>
<form name= "Calc" id= "Calc" action= "" >
<table border= "1" >
<TD colspan= "4" ><input type= "text" name= "expr" size= "" action= "compute (this.form)"/></td>
<tr>
<td><input type= "button" value= "7" onclick= "Enter (This.form,seven)"/></td>
<td><input type= "button" value= "8" onclick= "Enter (this.form,eight)"/></td>
<td><input type= "button" value= "9" onclick= "Enter (this.form,nine)"/></td>
<td><input type= "button" value= "/" onclick= "Enter (this.form,divide)"/></td>
</tr>
<tr>
<td><input type= "button" value= "4" onclick= "Enter (this.form,four)"/></td>
<td><input type= "button" value= "5" onclick= "Enter (this.form,five)"/></td>
<td><input type= "button" value= "6" onclick= "Enter (this.form,six)"/></td>
<td><input type= "button" value= "*" onclick= "Enter (this.form,multiply)"/></td>
</tr>
<tr>
<td><input type= "button" value= "1" onclick= "Enter (this.form,one)"/></td>
<td><input type= "button" value= "2" onclick= "Enter (this.form,two)"/></td>
<td><input type= "button" value= "3" onclick= "Enter (this.form,three)"/></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,zero)"/></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" onclick= "Form.reset ()"/></td>
</tr>
</table>
</form>
</body>
is not super NB code, the great God-Class!