El método de este artículo es súper simple, y vale la pena recomendar las ideas. Consulte ello.
La copia del código es la siguiente:
<! Doctype html>
<html>
<Evista>
<meta http-equiv = "content-type" content = "text /html; charset = utf-8" />
<title> JavaScript Calculadora simple </title>
<script>
// Defina la variable global var one = "1";
var dos = "2";
var tres = "3";
var cuatro = "4";
var cinco = "5";
var seis = "6";
var siete = "7";
var ocho = "8";
var nueve = "9";
var cero = "0";
var plus = "+", minus = "-", multiply = "*", divide = "/", decimal = ".";
función enter (obj, string) {
obj.expr.value+= string;
}
function Compute (obj) {// Haga clic en la función igual al botón "=" para llamar; obj.expr.value = eval (obj.expr.value); // use js para obtener el método eval () para calcular el nombre como la fórmula en expr}
</script>
</ablo>
<Body>
<form de nombre = "calc" id = "calc" action = "">
<Table>
<td colspan = "4"> <input type = "text" name = "expr" size = "30" Action = "Compute (this.form)" /> </td>
<tr>
<TD> <input type = "button" value = "7" onClick = "Enter (this.form, siete)" /> </td>
<TD> <input type = "button" value = "8" onClick = "Enter (this.form, ocho)" /> </td>
<TD> <input type = "button" value = "9" onClick = "Enter (this.form, nueve)" /> </td>
<TD> <input type = "Button" value = " /" onClick = "Enter (this.form, divide)" /> </td>
</tr>
<tr>
<TD> <input type = "Button" value = "4" onClick = "Enter (this.form, cuatro)" /> </td>
<TD> <input type = "button" value = "5" onClick = "Enter (this.form, cinco)" /> </td>
<TD> <input type = "button" value = "6" onClick = "Enter (this.Form, Six)" /> </td>
<TD> <input type = "Button" value = " *" onClick = "Enter (this.form, multiplicar)" /> </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, dos)" /> </td>
<TD> <input type = "button" value = "3" onClick = "Enter (this.form, tres)" /> </td>
<TD> <input type = "Button" Value = " -" onClick = "Enter (this.form, menos)" /> </td>
</tr>
<tr>
<td colspan = "2"> <input type = "button" value = "0" onClick = "Enter (this.form, cero)" /> </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>
</html>
¿Es un código Super NB, un nivel maestro!