<html>
<head>
<script>
var flag = true;
function getNum(num){
if(!flag){
document.getElementById('res').value = '';
flag = true;
}
document.getElementById('res').value += num;
}
function getResult(){
var result = eval(document.getElementById('res').value);
document.getElementById('res').value = result;
flag = false;
}
</script>
</head>
<body>
<table border='1px' width='300px'>
<caption>计算器</caption>
<tr>
<td colspan='4'><input type='text' id='res' size=47></td>
</tr>
<tr>
<td><input type='button' value='1' style="width:75px" οnclick="getNum(1)"></td>
<td><input type='button' value='2' style="width:75px" οnclick="getNum(2)"></td>
<td><input type='button' value='3' style="width:75px" οnclick="getNum(3)"></td>
<td><input type='button' value='+' style="width:75px" οnclick="getNum('+')"></td>
</tr>
<tr>
<td><input type='button' value='4' style="width:75px" οnclick="getNum(4)"></td>
<td><input type='button' value='5' style="width:75px" οnclick="getNum(5)"></td>
<td><input type='button' value='6' style="width:75px" οnclick="getNum(6)"></td>
<td><input type='button' value='-' style="width:75px" οnclick="getNum('-')"></td>
</tr>
<tr>
<td><input type='button' value='7' style="width:75px" οnclick="getNum(7)"></td>
<td><input type='button' value='8' style="width:75px" οnclick="getNum(8)"></td>
<td><input type='button' value='9' style="width:75px" οnclick="getNum(9)"></td>
<td><input type='button' value='*' style="width:75px" οnclick="getNum('*')"></td>
</tr>
<tr>
<td><input type='button' value='0' style="width:75px" οnclick="getNum(0)"></td>
<td><input type='button' value='.' style="width:75px" οnclick="getNum('.')"></td>
<td><input type='button' value='=' style="width:75px" οnclick="getResult()"></td>
<td><input type='button' value='/' style="width:75px" οnclick="getNum('/')"></td>
</tr>
</table>
</body>
</html>
<head>
<script>
var flag = true;
function getNum(num){
if(!flag){
document.getElementById('res').value = '';
flag = true;
}
document.getElementById('res').value += num;
}
function getResult(){
var result = eval(document.getElementById('res').value);
document.getElementById('res').value = result;
flag = false;
}
</script>
</head>
<body>
<table border='1px' width='300px'>
<caption>计算器</caption>
<tr>
<td colspan='4'><input type='text' id='res' size=47></td>
</tr>
<tr>
<td><input type='button' value='1' style="width:75px" οnclick="getNum(1)"></td>
<td><input type='button' value='2' style="width:75px" οnclick="getNum(2)"></td>
<td><input type='button' value='3' style="width:75px" οnclick="getNum(3)"></td>
<td><input type='button' value='+' style="width:75px" οnclick="getNum('+')"></td>
</tr>
<tr>
<td><input type='button' value='4' style="width:75px" οnclick="getNum(4)"></td>
<td><input type='button' value='5' style="width:75px" οnclick="getNum(5)"></td>
<td><input type='button' value='6' style="width:75px" οnclick="getNum(6)"></td>
<td><input type='button' value='-' style="width:75px" οnclick="getNum('-')"></td>
</tr>
<tr>
<td><input type='button' value='7' style="width:75px" οnclick="getNum(7)"></td>
<td><input type='button' value='8' style="width:75px" οnclick="getNum(8)"></td>
<td><input type='button' value='9' style="width:75px" οnclick="getNum(9)"></td>
<td><input type='button' value='*' style="width:75px" οnclick="getNum('*')"></td>
</tr>
<tr>
<td><input type='button' value='0' style="width:75px" οnclick="getNum(0)"></td>
<td><input type='button' value='.' style="width:75px" οnclick="getNum('.')"></td>
<td><input type='button' value='=' style="width:75px" οnclick="getResult()"></td>
<td><input type='button' value='/' style="width:75px" οnclick="getNum('/')"></td>
</tr>
</table>
</body>
</html>