新增负号

main
黄伊雯 1 month ago
parent 6715221fd9
commit ceb77e8794

@ -82,6 +82,7 @@
<button onclick="compute()">=</button> <button onclick="compute()">=</button>
<button onclick="chooseOperation('+')">+</button> <button onclick="chooseOperation('+')">+</button>
<button onclick="chooseOperation('%')">%</button> <button onclick="chooseOperation('%')">%</button>
<button onclick="appendNumber('-')">±</button>
</div> </div>
</div> </div>
@ -94,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();
} }
@ -150,4 +152,4 @@
} }
</script> </script>
</body> </body>
</html> </html>

Loading…
Cancel
Save