<!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=utf-8" />
<title>js-计算器</title>
</head>
<script language="javascript" type="text/javascript">
var clearmsg=false;
//获取点击获得的参数
function getNum(num){
var objResult = document.getElementById("result");
if(clearmsg){
objResult.value ="";
clearmsg=false;
}
//将获得的值进行累加
objResult.value += num;
}
//进行计算
function getResult(){
var objResult = document.getElementById("result");
objResult.value = objResult.value + "=" + eval(objResult.value);
clearmsg=true;
}
</script>
<body>
<table width="250" border="1" align="center">
<caption>js-计算器</caption>
<tr>
<td colspan="4"><input type="text" name="result" id="result" size="40"/></td>
</tr>
<tr>
<td><input type="button" value=" 1 " οnclick="getNum(1)"/></td>
<td><input type="button" value=" 2 " οnclick="getNum(2)"/></td>
<td><input type="button" value=" 3 " οnclick="getNum(3)"/></td>
<td><input type="button" value=" + " οnclick="getNum('+')"/></td>
</tr>
<tr>
<td><input type="button" value=" 4 " οnclick="getNum(4)"/></td>
<td><input type="button" value=" 5 " οnclick="getNum(5)"/></td>
<td><input type="button" value=" 6 " οnclick="getNum(6)"/></td>
<td><input type="button" value=" — " οnclick="getNum('-')"/></td>
</tr>
<tr>
<td><input type="button" value=" 7 " οnclick="getNum(7)"/></td>
<td><input type="button" value=" 8 " οnclick="getNum(8)"/></td>
<td><input type="button" value=" 9 " οnclick="getNum(9)"/></td>
<td><input type="button" value=" * " οnclick="getNum('*')"/></td>
</tr>
<tr>
<td><input type="button" value=" 0 " οnclick="getNum(0)"/></td>
<td><input type="button" value=" . " οnclick="getNum('.')"/></td>
<td><input type="button" value=" = " οnclick="getResult()"/></td>
<td><input type="button" value=" / " οnclick="getNum('/')"/></td>
</tr>
</table>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js-计算器</title>
</head>
<script language="javascript" type="text/javascript">
var clearmsg=false;
//获取点击获得的参数
function getNum(num){
var objResult = document.getElementById("result");
if(clearmsg){
objResult.value ="";
clearmsg=false;
}
//将获得的值进行累加
objResult.value += num;
}
//进行计算
function getResult(){
var objResult = document.getElementById("result");
objResult.value = objResult.value + "=" + eval(objResult.value);
clearmsg=true;
}
</script>
<body>
<table width="250" border="1" align="center">
<caption>js-计算器</caption>
<tr>
<td colspan="4"><input type="text" name="result" id="result" size="40"/></td>
</tr>
<tr>
<td><input type="button" value=" 1 " οnclick="getNum(1)"/></td>
<td><input type="button" value=" 2 " οnclick="getNum(2)"/></td>
<td><input type="button" value=" 3 " οnclick="getNum(3)"/></td>
<td><input type="button" value=" + " οnclick="getNum('+')"/></td>
</tr>
<tr>
<td><input type="button" value=" 4 " οnclick="getNum(4)"/></td>
<td><input type="button" value=" 5 " οnclick="getNum(5)"/></td>
<td><input type="button" value=" 6 " οnclick="getNum(6)"/></td>
<td><input type="button" value=" — " οnclick="getNum('-')"/></td>
</tr>
<tr>
<td><input type="button" value=" 7 " οnclick="getNum(7)"/></td>
<td><input type="button" value=" 8 " οnclick="getNum(8)"/></td>
<td><input type="button" value=" 9 " οnclick="getNum(9)"/></td>
<td><input type="button" value=" * " οnclick="getNum('*')"/></td>
</tr>
<tr>
<td><input type="button" value=" 0 " οnclick="getNum(0)"/></td>
<td><input type="button" value=" . " οnclick="getNum('.')"/></td>
<td><input type="button" value=" = " οnclick="getResult()"/></td>
<td><input type="button" value=" / " οnclick="getNum('/')"/></td>
</tr>
</table>
</body>
</html>