Compare commits

...

No commits in common. 'master' and 'main' have entirely different histories.
master ... main

@ -0,0 +1,2 @@
# jisuanqi

@ -0,0 +1,4 @@
public class Test {
}

@ -26,7 +26,7 @@
width: 100%; width: 100%;
height: 50px; height: 50px;
margin-bottom: 10px; margin-bottom: 10px;
padding: 10px; padding: 0px;
font-size: 24px; font-size: 24px;
text-align: right; text-align: right;
border: none; border: none;
@ -61,7 +61,7 @@
</style> </style>
</head> </head>
<body> <body>
<div class="calculator"> <div class="calculator">
<input type="text" id="display" disabled> <input type="text" id="display" disabled>
<div class="buttons"> <div class="buttons">
<button onclick="clearDisplay()">C</button> <button onclick="clearDisplay()">C</button>
@ -81,10 +81,12 @@
<button onclick="appendNumber('.')">.</button> <button onclick="appendNumber('.')">.</button>
<button onclick="compute()">=</button> <button onclick="compute()">=</button>
<button onclick="chooseOperation('+')">+</button> <button onclick="chooseOperation('+')">+</button>
<button onclick="chooseOperation('%')">%</button>
<button onclick="appendNumber('-')">±</button>
</div> </div>
</div> </div>
<script> <script>
let currentOperand = ''; let currentOperand = '';
let previousOperand = ''; let previousOperand = '';
let operation = undefined; let operation = undefined;
@ -93,6 +95,7 @@
function appendNumber(number) { function appendNumber(number) {
if (number === '.' && currentOperand.includes('.')) return; if (number === '.' && currentOperand.includes('.')) return;
if (number === '-' && currentOperand.length > 0) return; // 防止在数字中间添加负号
currentOperand += number; currentOperand += number;
updateDisplay(); updateDisplay();
} }
@ -125,6 +128,9 @@
case '/': case '/':
computation = prev / current; computation = prev / current;
break; break;
case '%':
computation = prev % current;
break;
default: default:
return; return;
} }
@ -144,6 +150,6 @@
function updateDisplay() { function updateDisplay() {
display.value = currentOperand; display.value = currentOperand;
} }
</script> </script>
</body> </body>
</html> </html>
Loading…
Cancel
Save