<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>作业5</title>
<style>
body {
background-color: #c5c5c5;
}
button {
width: 50px;
}
</style>
</head>
<body>
<table border="1" cellspacing="1" bordercolor="#f0f0f0">
<from>
<tr>
<td colspan="4"><input style="width: 210px;text-align:right" readonly type="text" id="str" /></td>
</tr>
<tr>
<td><button onclick="f('7')">7</button></td>
<td><button onclick="f('8')">8</button></td>
<td><button onclick="f('9')">9</button></td>
<td><button onclick="f('+')">+</button></td>
</tr>
<tr>
<td><button onclick="f('4')">4</button></td>
<td><button onclick="f('5')">5</button></td>
<td><button onclick="f('6')">6</button></td>
<td><button onclick="f('-')">-</button></td>
</tr>
<tr>
<td><button onclick="f('1')">1</button></td>
<td><button onclick="f('2')">2</button></td>
<td><button onclick="f('3')">3</button></td>
<td><button onclick="f('*')">*</button></td>
</tr>
<tr>
<td><button onclick="f('0')">0</button></td>
<td><button onclick="f('C')">C</button></td>
<td><button onclick="f('/')">/</button></td>
<td><button onclick="f('=')">=</button></td>
</tr>
</from>
</table>
<script>
function f(str) {
if (str == "C") {
document.getElementById("str").value = ""
} else {
document.getElementById("str").value += str
var s = document.getElementById("str").value
if (str == '=') {
var numbers = s.replace('=', '')
console.log(numbers.indexOf('-'))
if (numbers.indexOf('+') != -1) {
var numbers = numbers.split('+')
document.getElementById("str").value += parseInt(numbers[0]) + parseInt(numbers[1])
} else if (numbers.indexOf('-') != -1) {
var numbers = numbers.split('-')
document.getElementById("str").value += parseInt(numbers[0]) - parseInt(numbers[1])
} else if (numbers.indexOf('*') != -1) {
var numbers = numbers.split('*')
document.getElementById("str").value += parseInt(numbers[0]) * parseInt(numbers[1])
} else if (numbers.indexOf('/') != -1) {
var numbers = numbers.split('/')
document.getElementById("str").value += parseInt(numbers[0]) / parseInt(numbers[1])
}
}
}
}
</script>
</body>
</html>