这篇文章介绍了网页版计算器的简单实现代码
有需要的朋友可以参考一下
复制代码 代码如下:
<!DOCTYPE html PUBLIC "//WC//DTD XHTML Transitional//EN" "
<html xmlns="
<head>
<meta httpequiv="ContentType" content="text/html; charset=gb" />
<title>计算器</title>
<script language="javascript" type="text/javascript">
var clearFlag=false;
function getNum(num){
//alert(num);
var objresult=documentgetElementById("result");
if(clearFlag){
objresultvalue="";
clearFlag=false;
}
//alert(objresult);
objresultvalue+=num;
}
function getResult(){
var objresult=documentgetElementById("result");
objresultvalue=objresultvalue+"="+eval(objresultvalue);
clearFlag=true;
}
</script>
</head>
<body>
<table width="" border="" cellpadding="">
<tr>
<td colspan=""><input type="text" name="result" id="result" size=""></td>
</tr>
<tr>
<td width=""><input type="button" value=" " onclick="getNum()"></td>
<td width=""><input type="button" value=" " onclick="getNum()"></td>
<td width=""><input type="button" value=" " onclick="getNum()"></td>
<td width=""><input type="button" value=" + " onclick="getNum(+)"></td>
</tr>
<tr>
<td><input type="button" value=" " onclick="getNum()"></td>
<td><input type="button" value=" " onclick="getNum()"></td>
<td><input type="button" value=" " onclick="getNum()"></td>
<td><input type="button" value=" " onclick="getNum()"></td>
</tr>
<tr>
<td><input type="button" value=" " onclick="getNum()"></td>
<td><input type="button" value=" " onclick="getNum()"></td>
<td><input type="button" value=" " onclick="getNum()"></td>
<td><input type="button" value=" * " onclick="getNum(*)"></td>
</tr>
<tr>
<td><input type="button" value=" " onclick="getNum()"></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>