This article introduces the web version of the calculator simple implementation code, the need for friends can refer to the
copy code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv= "Content-type" content= "text/html"; charset=gb2312 "/>
<title> Calculator </title>
<script language= "javascript" type= "Text/javascript" >
var clearflag=false;
function Getnum (num) {
//alert (num);
var Objresult=document.getelementbyid ("result");
if (clearflag) {
objresult.value= "";
Clearflag=false;
}
//alert (Objresult);
Objresult.value+=num;
}
function GetResult () {
var Objresult=document.getelementbyid ("result");
objresult.value=objresult.value+ "=" +eval (objresult.value);
clearflag=true;
}
</script>
</head>
<body>
<table width= border= "1" cellpadding= "2" >
<tr>
<td colspan= "4" ><input type= "text" name= "result" id= "result" size= "></td>
"
</tr>
<tr>
<td width= "><input type=" button "value=" 1 "onclick=" Getnum (1) "></td>
<td width= "><input type=" button "value=" 2 "onclick=" Getnum (2) "></td>
<TD width= "Wuyi" ><input type= "button" value= "3" onclick= "Getnum (3)" ></td>
<td width= "><input type=" button "value=" + "onclick=" getnum (' + ') "></td>
</tr>
<tr>
<td><input type= "button" value= "4" onclick= "Getnum (4)" ></td>
<td><input type= "button" value= "5" onclick= "Getnum (5)" ></td>
<td><input type= "button" value= "6" onclick= "Getnum (6)" ></td>
<td><input type= "button" value= "onclick=" getnum ('-') "></td>
</tr>
<tr>
<td><input type= "button" value= "7" onclick= "Getnum (7)" ></td>
<td><input type= "button" value= "8" onclick= "Getnum (8)" ></td>
<td><input type= "button" value= "9" onclick= "Getnum (9)" ></td>
<td><input type= "button" value= "*" onclick= "getnum (' * ')" ></td>
</tr>
<tr>
<td><input type= "button" value= "0" onclick= "getnum (0)" ></td>
<td><input type= "button" value=. "Onclick=" Getnum ('. ') " ></td>
<td><input type= "button" value= "=" onclick= "GetResult ()" ></td>
<td><input type= "button" value= "/" onclick= "getnum ('/')" ></td>
</tr>
</table>
</body>
</html>