{"id":569,"date":"2025-03-06T17:19:31","date_gmt":"2025-03-06T09:19:31","guid":{"rendered":"https:\/\/blog.guguan.us.kg\/?p=569"},"modified":"2026-04-22T01:42:15","modified_gmt":"2026-04-21T17:42:15","slug":"%e5%9c%a8%e7%ba%bf%e8%ae%a1%e7%ae%97%e5%99%a8","status":"publish","type":"post","link":"https:\/\/blog.guguan.us.kg\/?p=569","title":{"rendered":"\u5728\u7ebf\u8ba1\u7b97\u5668"},"content":{"rendered":"\n<style>\n    .calculator {\n        width: 300px;\n        margin: 50px auto;\n        padding: 20px;\n        border: 1px solid #ccc;\n        border-radius: 5px;\n        box-shadow: 0 0 10px rgba(0,0,0,0.1);\n    }\n    \n    .expression-display {\n        width: 100%;\n        height: 30px;\n        margin-bottom: 5px;\n        padding: 5px;\n        font-size: 16px;\n        text-align: right;\n        color: #888;\n        box-sizing: border-box;\n        border: none;\n        outline: none;\n        background-color: transparent;\n        color: var(--wp--preset--color--contrast);\n    }\n\n    .display {\n        width: 100%;\n        height: 50px;\n        margin-bottom: 10px;\n        padding: 10px;\n        font-size: 20px;\n        text-align: right;\n        box-sizing: border-box;\n        border: none;\n        outline: none;\n        background-color: transparent;\n        color: var(--wp--preset--color--contrast);\n    }\n    \n    .buttons {\n        display: grid;\n        grid-template-columns: repeat(4, 1fr);\n        gap: 5px;\n    }\n    \n    .calculator button {\n        padding: 15px;\n        font-size: 18px;\n        cursor: pointer;\n        background-color: #f0f0f0;\n        border: 1px solid #ddd;\n        border-radius: 5px;\n    }\n    \n    .calculator button:hover {\n        background-color: #e0e0e0;\n    }\n    \n    .calculator .operator {\n        background-color: #f8a51d;\n        color: white;\n    }\n    \n    .calculator .operator:hover {\n        background-color: #e59400;\n    }\n<\/style>\n<div class=\"calculator\">\n\t<input type=\"text\" class=\"expression-display\" id=\"expressionDisplay\" readonly title=\"\u8868\u8fbe\u5f0f\">\n\t<input type=\"text\" class=\"display\" id=\"display\" value=\"0\" readonly title=\"\u7ed3\u679c\">\n\t<div class=\"buttons\">\n\t\t<button type=\"button\" onclick=\"clearEntry()\">CE<\/button>\n\t\t<button type=\"reset\" onclick=\"clearDisplay()\">C<\/button>\n\t\t<button type=\"button\" onclick=\"backspace()\">\u2190<\/button>\n\t\t<button type=\"button\" class=\"operator\" onclick=\"handleOperator('\/')\">\/<\/button>\n\t\t<button type=\"button\" onclick=\"appendNumber('7')\">7<\/button>\n\t\t<button type=\"button\" onclick=\"appendNumber('8')\">8<\/button>\n\t\t<button type=\"button\" onclick=\"appendNumber('9')\">9<\/button>\n\t\t<button type=\"button\" class=\"operator\" onclick=\"handleOperator('*')\">\u00d7<\/button>\n\t\t<button type=\"button\" onclick=\"appendNumber('4')\">4<\/button>\n\t\t<button type=\"button\" onclick=\"appendNumber('5')\">5<\/button>\n\t\t<button type=\"button\" onclick=\"appendNumber('6')\">6<\/button>\n\t\t<button type=\"button\" class=\"operator\" onclick=\"handleOperator('-')\">&#8211;<\/button>\n\t\t<button type=\"button\" onclick=\"appendNumber('1')\">1<\/button>\n\t\t<button type=\"button\" onclick=\"appendNumber('2')\">2<\/button>\n\t\t<button type=\"button\" onclick=\"appendNumber('3')\">3<\/button>\n\t\t<button type=\"button\" class=\"operator\" onclick=\"handleOperator('+')\">+<\/button>\n\t\t<button type=\"button\" onclick=\"toggleSign()\">\u00b1<\/button>\n\t\t<button type=\"button\" onclick=\"appendNumber('0')\">0<\/button>\n\t\t<button type=\"button\" onclick=\"appendNumber('.')\">.<\/button>\n\t\t<button type=\"button\" onclick=\"calculate()\">=<\/button>\n\t<\/div>\n<\/div>\n\n<script>\n\tconst display = document.getElementById('display');\n\tconst expressionDisplay = document.getElementById('expressionDisplay');\n\n\t\/\/ \u72b6\u6001\u673a\u72b6\u6001\n\tconst STATES = {\n\t\tINITIAL: 'INITIAL',                 \/\/ \u521d\u59cb\u72b6\u6001\uff0c\u7b49\u5f85\u7b2c\u4e00\u4e2a\u6570\u5b57\u8f93\u5165\u6216\u64cd\u4f5c\u7b26\n\t\tFIRST_INPUT: 'FIRST_INPUT',         \/\/ \u6b63\u5728\u8f93\u5165\u7b2c\u4e00\u4e2a\u6570\u5b57\n\t\tAWAITING_SECOND_INPUT: 'AWAITING_SECOND_INPUT', \/\/ \u7b49\u5f85\u7b2c\u4e8c\u4e2a\u6570\u5b57\u8f93\u5165 (\u64cd\u4f5c\u7b26\u5df2\u9009\u62e9)\n\t\tSECOND_INPUT: 'SECOND_INPUT'        \/\/ \u6b63\u5728\u8f93\u5165\u7b2c\u4e8c\u4e2a\u6570\u5b57\n\t};\n\n\t\/\/ \u8ba1\u7b97\u5668\u72b6\u6001\u53d8\u91cf\n\tlet state = STATES.INITIAL;             \/\/ \u5f53\u524d\u72b6\u6001\n\tlet firstNumber = null;                 \/\/ \u7b2c\u4e00\u4e2a\u64cd\u4f5c\u6570\n\tlet operator = null;                    \/\/ \u64cd\u4f5c\u7b26\n\tlet secondNumber = null;                \/\/ \u7b2c\u4e8c\u4e2a\u64cd\u4f5c\u6570\n\tlet lastResult = null;                  \/\/ \u7528\u4e8e\u5b58\u50a8\u4e0a\u6b21\u7684\u8ba1\u7b97\u7ed3\u679c\uff0c\u4ee5\u4fbf\u5728 INITIAL \u72b6\u6001\u4e0b\u8fdb\u884c\u64cd\u4f5c\n\n\t\/**\n\t * \u5411\u5f53\u524d\u663e\u793a\u5c4f\u8ffd\u52a0\u6570\u5b57\u6216\u5c0f\u6570\u70b9\u3002\n\t * @param {string} num - \u8981\u8ffd\u52a0\u7684\u6570\u5b57\u6216\u5c0f\u6570\u70b9\u3002\n\t *\/\n\tfunction appendNumber(num) {\n\t\tif (state === STATES.INITIAL) {\n\t\t\t\/\/ \u5982\u679c\u662f\u521d\u59cb\u72b6\u6001\uff0c\u66ff\u6362 \"0\" \u6216\u4e0a\u6b21\u7ed3\u679c\u4e3a\u65b0\u6570\u5b57\n\t\t\texpressionDisplay.value = '';\n\t\t\tdisplay.value = num === '.' ? '0.' : num;\n\t\t\tstate = STATES.FIRST_INPUT;\n\t\t} else if (state === STATES.FIRST_INPUT) {\n\t\t\t\/\/ \u5982\u679c\u6b63\u5728\u8f93\u5165\u7b2c\u4e00\u4e2a\u6570\u5b57\uff0c\u5219\u8ffd\u52a0\u5230\u5f53\u524d\u6570\u5b57\n\t\t\tif (num === '.' && display.value.includes('.')) return; \/\/ \u907f\u514d\u91cd\u590d\u7684\u5c0f\u6570\u70b9\n\t\t\tif (display.value === '0' && num !== '.') {\n\t\t\t\tdisplay.value = num; \/\/ \u5982\u679c\u5f53\u524d\u662f0\u4e14\u8f93\u5165\u4e0d\u662f\u5c0f\u6570\u70b9\uff0c\u5219\u66ff\u63620\n\t\t\t} else {\n\t\t\t\tdisplay.value += num; \/\/ \u5426\u5219\u8ffd\u52a0\n\t\t\t}\n\t\t} else if (state === STATES.AWAITING_SECOND_INPUT) {\n\t\t\t\/\/ \u5982\u679c\u5728\u7b49\u5f85\u7b2c\u4e8c\u4e2a\u6570\u5b57\u8f93\u5165\n\t\t\tdisplay.value = num === '.' ? '0.' : num; \/\/ \u5f00\u59cb\u8f93\u5165\u65b0\u7684\u7b2c\u4e8c\u4e2a\u6570\u5b57\n\t\t\tsecondNumber = display.value;\n\t\t\tstate = STATES.SECOND_INPUT; \/\/ \u5207\u6362\u5230\u6b63\u5728\u8f93\u5165\u7b2c\u4e8c\u4e2a\u6570\u5b57\u7684\u72b6\u6001\n\t\t} else if (state === STATES.SECOND_INPUT) {\n\t\t\t\/\/ \u5982\u679c\u6b63\u5728\u8f93\u5165\u7b2c\u4e8c\u4e2a\u6570\u5b57\uff0c\u5219\u8ffd\u52a0\u5230\u5f53\u524d\u6570\u5b57\n\t\t\tif (num === '.' && display.value.includes('.')) return; \/\/ \u907f\u514d\u91cd\u590d\u7684\u5c0f\u6570\u70b9\n\t\t\tif (display.value === '0' && num !== '.') {\n\t\t\t\tdisplay.value = num; \/\/ \u5982\u679c\u5f53\u524d\u662f0\u4e14\u8f93\u5165\u4e0d\u662f\u5c0f\u6570\u70b9\uff0c\u5219\u66ff\u63620\n\t\t\t} else {\n\t\t\t\tdisplay.value += num; \/\/ \u5426\u5219\u8ffd\u52a0\n\t\t\t}\n\t\t\tsecondNumber = display.value; \/\/ \u66f4\u65b0 secondNumber\n\t\t}\n\t}\n\n\t\/**\n\t * \u5904\u7406\u64cd\u4f5c\u7b26\u8f93\u5165\u3002\n\t * @param {string} op - \u64cd\u4f5c\u7b26\uff08'+', '-', '*', '\/'\uff09\u3002\n\t *\/\n\tfunction handleOperator(op) {\n\t\tif (state === STATES.INITIAL || state === STATES.FIRST_INPUT) {\n\t\t\t\/\/ \u5982\u679c\u662f\u521d\u59cb\u72b6\u6001\u6216\u6b63\u5728\u8f93\u5165\u7b2c\u4e00\u4e2a\u6570\u5b57\uff0c\u5b58\u50a8\u7b2c\u4e00\u4e2a\u64cd\u4f5c\u6570\u548c\u64cd\u4f5c\u7b26\n\t\t\tfirstNumber = Number(display.value);\n\t\t\toperator = op;\n\t\t\texpressionDisplay.value = `${firstNumber} ${op} `;\n\t\t\tstate = STATES.AWAITING_SECOND_INPUT; \/\/ \u5207\u6362\u5230\u7b49\u5f85\u7b2c\u4e8c\u4e2a\u6570\u5b57\u8f93\u5165\u7684\u72b6\u6001\n\t\t\tsecondNumber = null; \/\/ \u91cd\u7f6e\u7b2c\u4e8c\u4e2a\u64cd\u4f5c\u6570\n\t\t} else if (state === STATES.AWAITING_SECOND_INPUT) {\n\t\t\t\/\/ \u5982\u679c\u5728\u7b49\u5f85\u7b2c\u4e8c\u4e2a\u6570\u5b57\u65f6\u53c8\u8f93\u5165\u4e86\u64cd\u4f5c\u7b26\uff0c\u76f4\u63a5\u66f4\u65b0\u64cd\u4f5c\u7b26\n\t\t\toperator = op;\n\t\t\texpressionDisplay.value = `${firstNumber} ${op} `;\n\t\t\t\/\/ \u72b6\u6001\u4fdd\u6301 AWAITING_SECOND_INPUT\n\t\t} else if (state === STATES.SECOND_INPUT) {\n\t\t\t\/\/ \u5982\u679c\u6b63\u5728\u8f93\u5165\u7b2c\u4e8c\u4e2a\u6570\u5b57\uff0c\u8ba1\u7b97\u5f53\u524d\u8868\u8fbe\u5f0f\uff0c\u7136\u540e\u51c6\u5907\u65b0\u7684\u64cd\u4f5c\u7b26\n\t\t\tif (secondNumber !== null && operator !== null) {\n\t\t\t\tsecondNumber = Number(display.value);\n\t\t\t\ttry {\n\t\t\t\t\tconst result = compute(firstNumber, operator, secondNumber);\n\t\t\t\t\tdisplay.value = result;\n\t\t\t\t\texpressionDisplay.value = `${firstNumber} ${operator} ${secondNumber} =`;\n\t\t\t\t\tfirstNumber = result; \/\/ \u5c06\u7ed3\u679c\u4f5c\u4e3a\u65b0\u7684 firstNumber\uff0c\u7528\u4e8e\u94fe\u5f0f\u64cd\u4f5c\n\t\t\t\t\tlastResult = result;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tdisplay.value = 'Error';\n\t\t\t\t\treset();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\toperator = op;\n\t\t\texpressionDisplay.value = `${firstNumber} ${op} `; \/\/ \u66f4\u65b0\u8868\u8fbe\u5f0f\u663e\u793a\uff0c\u663e\u793a\u65b0\u7684\u64cd\u4f5c\u7b26\n\t\t\tstate = STATES.AWAITING_SECOND_INPUT; \/\/ \u5207\u6362\u5230\u7b49\u5f85\u7b2c\u4e8c\u4e2a\u6570\u5b57\u8f93\u5165\u7684\u72b6\u6001\n\t\t\tsecondNumber = null; \/\/ \u91cd\u7f6e secondNumber\uff0c\u7528\u4e8e\u4e0b\u4e00\u4e2a\u8f93\u5165\n\t\t}\n\t}\n\n\t\/**\n\t * \u6267\u884c\u8ba1\u7b97\u3002\n\t *\/\n\tfunction calculate() {\n\t\tif (state === STATES.FIRST_INPUT) {\n\t\t\t\/\/ \u5982\u679c\u53ea\u8f93\u5165\u4e86\u7b2c\u4e00\u4e2a\u6570\u5b57\u5c31\u6309\u4e86\u7b49\u53f7\uff0c\u89c6\u4e3a \"\u6570\u5b57 =\"\n\t\t\tlastResult = Number(display.value);\n\t\t\tdisplay.value = lastResult;\n\t\t\texpressionDisplay.value = `${lastResult} =`;\n\t\t\treset(); \/\/ \u91cd\u7f6e\u4ee5\u51c6\u5907\u65b0\u7684\u8ba1\u7b97\n\t\t\tstate = STATES.INITIAL;\n\t\t} else if (state === STATES.SECOND_INPUT || state === STATES.AWAITING_SECOND_INPUT) {\n\t\t\t\/\/ \u5982\u679c\u6b63\u5728\u8f93\u5165\u7b2c\u4e8c\u4e2a\u6570\u5b57\uff0c\u8ba1\u7b97\u7ed3\u679c\n\t\t\tsecondNumber = Number(display.value);\n\t\t\ttry {\n\t\t\t\tconst result = compute(firstNumber, operator, secondNumber);\n\t\t\t\texpressionDisplay.value = `${firstNumber} ${operator} ${secondNumber} =`;\n\t\t\t\tdisplay.value = result;\n\t\t\t\tlastResult = result;\n\t\t\t\treset(); \/\/ \u91cd\u7f6e\u4ee5\u51c6\u5907\u65b0\u7684\u8ba1\u7b97\n\t\t\t\tstate = STATES.INITIAL;\n\t\t\t} catch (error) {\n\t\t\t\tdisplay.value = 'Error';\n\t\t\t\treset();\n\t\t\t}\n\t\t}\n\t}\n\n\t\/**\n\t * \u6267\u884c\u5b9e\u9645\u7684\u6570\u5b66\u8ba1\u7b97\u3002\n\t * @param {number} a - \u7b2c\u4e00\u4e2a\u64cd\u4f5c\u6570\u3002\n\t * @param {string} op - \u64cd\u4f5c\u7b26\u3002\n\t * @param {number} b - \u7b2c\u4e8c\u4e2a\u64cd\u4f5c\u6570\u3002\n\t * @returns {number} - \u8ba1\u7b97\u7ed3\u679c\u3002\n\t * @throws {Error} - \u9664\u4ee5\u96f6\u6216\u65e0\u6548\u64cd\u4f5c\u7b26\u9519\u8bef\u3002\n\t *\/\n\tfunction compute(a, op, b) {\n\t\tswitch (op) {\n\t\t\tcase '+': return a + b;\n\t\t\tcase '-': return a - b;\n\t\t\tcase '*': return a * b;\n\t\t\tcase '\/':\n\t\t\t\tif (b === 0) throw new Error('Division by zero'); \/\/ \u629b\u51fa\u9664\u4ee5\u96f6\u9519\u8bef\n\t\t\t\treturn a \/ b;\n\t\t\tdefault: throw new Error('Invalid operator'); \/\/ \u629b\u51fa\u65e0\u6548\u64cd\u4f5c\u7b26\u9519\u8bef\n\t\t}\n\t}\n\n\t\/**\n\t * \u6e05\u7a7a\u663e\u793a\u5c4f\u5e76\u91cd\u7f6e\u8ba1\u7b97\u5668\u72b6\u6001\u3002\n\t *\/\n\tfunction clearDisplay() {\n\t\tdisplay.value = '0';\n\t\texpressionDisplay.value = '';\n\t\treset();\n\t\tstate = STATES.INITIAL;\n\t}\n\n\t\/**\n\t * \u6e05\u7a7a\u5f53\u524d\u8f93\u5165\uff08CE\uff09\u3002\n\t *\/\n\tfunction clearEntry() {\n\t\tif (state === STATES.FIRST_INPUT) {\n\t\t\tdisplay.value = '0';\n\t\t} else if (state === STATES.SECOND_INPUT || state === STATES.AWAITING_SECOND_INPUT) {\n\t\t\tdisplay.value = '0';\n\t\t\tsecondNumber = null; \/\/ \u6e05\u7a7a\u7b2c\u4e8c\u4e2a\u64cd\u4f5c\u6570\n\t\t} else if (state === STATES.INITIAL) {\n\t\t\texpressionDisplay.value = '';\n\t\t\tdisplay.value = '0';\n\t\t\tlastResult = null; \/\/ \u5728\u521d\u59cb\u72b6\u6001\u4e0b\u6309 CE \u4e5f\u6e05\u7a7a\u4e0a\u6b21\u7ed3\u679c\n\t\t}\n\t}\n\n\t\/**\n\t * \u5207\u6362\u5f53\u524d\u663e\u793a\u6570\u5b57\u7684\u6b63\u8d1f\u53f7\u3002\n\t *\/\n\tfunction toggleSign() {\n\t\tif (display.value !== '0' && display.value !== 'Error') {\n\t\t\tdisplay.value = display.value.startsWith('-')\n\t\t\t\t? display.value.slice(1) \/\/ \u5982\u679c\u662f\u8d1f\u6570\uff0c\u79fb\u9664\u8d1f\u53f7\n\t\t\t\t: '-' + display.value;   \/\/ \u5982\u679c\u662f\u6b63\u6570\uff0c\u6dfb\u52a0\u8d1f\u53f7\n\n\t\t\tif (state === STATES.FIRST_INPUT) {\n\t\t\t\t\/\/ \u66f4\u65b0\u53ef\u80fd\u4f5c\u4e3a firstNumber \u7684\u503c\n\t\t\t\tfirstNumber = Number(display.value);\n\t\t\t} else if (state === STATES.SECOND_INPUT || state === STATES.AWAITING_SECOND_INPUT) {\n\t\t\t\tsecondNumber = display.value;\n\t\t\t}\n\t\t}\n\t}\n\n\t\/**\n\t * \u6267\u884c\u9000\u683c\u64cd\u4f5c\uff0c\u5220\u9664\u663e\u793a\u5c4f\u4e0a\u7684\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\u3002\n\t *\/\n\tfunction backspace() {\n\t\tif (display.value === 'Error') {\n\t\t\tclearDisplay(); \/\/ \u5982\u679c\u5f53\u524d\u662f\u9519\u8bef\u72b6\u6001\uff0c\u76f4\u63a5\u6e05\u7a7a\n\t\t\treturn;\n\t\t}\n\n\t\tif (state === STATES.FIRST_INPUT || state === STATES.SECOND_INPUT) {\n\t\t\tif (display.value.length === 1 || (display.value.length === 2 && display.value.startsWith('-'))) {\n\t\t\t\tdisplay.value = '0'; \/\/ \u5982\u679c\u53ea\u5269\u4e00\u4e2a\u6570\u5b57\u6216\u8d1f\u53f7\u52a0\u4e00\u4e2a\u6570\u5b57\uff0c\u6e05\u7a7a\u4e3a0\n\t\t\t} else {\n\t\t\t\tdisplay.value = display.value.slice(0, -1); \/\/ \u5426\u5219\u5220\u9664\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\n\t\t\t}\n\n\t\t\tif (state === STATES.SECOND_INPUT) {\n\t\t\t\tsecondNumber = display.value === '0' ? null : display.value; \/\/ \u66f4\u65b0 secondNumber\n\t\t\t}\n\t\t} else if (state === STATES.AWAITING_SECOND_INPUT) {\n\t\t\t\/\/ \u5728\u7b49\u5f85\u8f93\u5165\u72b6\u6001\u6309\u9000\u683c\uff0c\u4e0d\u5f71\u54cd\u663e\u793a\u5c4f\uff0c\u4f46\u53ef\u4ee5\u8003\u8651\u6e05\u7a7a\u8868\u8fbe\u5f0f\u663e\u793a\n\t\t\texpressionDisplay.value = `${firstNumber} ${operator} `;\n\t\t} else if (state === STATES.INITIAL) {\n\t\t\texpressionDisplay.value = ''; \/\/ \u521d\u59cb\u72b6\u6001\u4e0b\u6309\u9000\u683c\uff0c\u6e05\u7a7a\u8868\u8fbe\u5f0f\u663e\u793a\n\t\t\t\/\/ display.value \u4fdd\u6301\u4e3a\u4e0a\u6b21\u7ed3\u679c\u6216 '0'\n\t\t}\n\t}\n\n\t\/**\n\t * \u91cd\u7f6e\u6240\u6709\u8ba1\u7b97\u5668\u5185\u90e8\u72b6\u6001\u53d8\u91cf\u3002\n\t *\/\n\tfunction reset() {\n\t\tfirstNumber = null;\n\t\toperator = null;\n\t\tsecondNumber = null;\n\t}\n\n\t\/\/ --- \u952e\u76d8\u8f93\u5165\u652f\u6301 ---\n\tdocument.addEventListener('keydown', (event) => {\n\t\tconst key = event.key; \/\/ \u83b7\u53d6\u6309\u4e0b\u7684\u952e\u7684\u503c\n\n\t\tif (\/[0-9]\/.test(key)) {\n\t\t\t\/\/ \u5982\u679c\u662f\u6570\u5b57\u952e (0-9)\n\t\t\tappendNumber(key);\n\t\t} else if (key === '.') {\n\t\t\t\/\/ \u5982\u679c\u662f\u5c0f\u6570\u70b9\n\t\t\tappendNumber(key);\n\t\t} else if (key === '+' || key === '-' || key === '*' || key === '\/') {\n\t\t\t\/\/ \u5982\u679c\u662f\u52a0\u51cf\u4e58\u9664\u8fd0\u7b97\u7b26\n\t\t\t\/\/ \u952e\u76d8\u4e0a\u7684 '*' \u5bf9\u5e94\u8ba1\u7b97\u5668\u7684 '\u00d7'\n\t\t\thandleOperator(key);\n\t\t} else if (key === 'Enter' || key === '=') {\n\t\t\t\/\/ \u5982\u679c\u662f\u56de\u8f66\u952e\u6216\u7b49\u53f7\u952e\n\t\t\tevent.preventDefault(); \/\/ \u963b\u6b62\u9ed8\u8ba4\u7684\u56de\u8f66\u884c\u4e3a\uff08\u4f8b\u5982\u63d0\u4ea4\u8868\u5355\uff09\n\t\t\tcalculate();\n\t\t} else if (key === 'Backspace') {\n\t\t\t\/\/ \u5982\u679c\u662f\u9000\u683c\u952e\n\t\t\tbackspace();\n\t\t} else if (key === 'Delete' || key === 'c' || key === 'C') {\n\t\t\t\/\/ 'Delete' \u952e\u6216 'c'\/'C' \u952e\u7528\u4e8e\u6e05\u7a7a\u6240\u6709 (Clear All)\n\t\t\tclearDisplay();\n\t\t} else if (key === 'Escape') {\n\t\t\t\/\/ 'Escape' \u952e\u7528\u4e8e\u6e05\u7a7a\u5f53\u524d\u8f93\u5165 (Clear Entry)\n\t\t\tclearEntry();\n\t\t}\n\t});\n<\/script>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e00\u4e2a\u7b80\u5355\u7684\u5728\u7ebf\u8ba1\u7b97\u5668\uff0c\u4f46\u662f\u5305\u542b\u4e86JavaScript\u7684\u4e00\u4e9b\u7279\u8272<\/p>\n\n\n\n<p class=\"has-small-font-size wp-block-paragraph\">(\u8bf7\u4e0d\u8981\u8ba1\u7b970.2+0.1\uff01)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u4e2a\u7b80\u5355\u7684\u5728\u7ebf\u8ba1\u7b97\u5668<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[140,83],"class_list":["post-569","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-tools","tag-83"],"_links":{"self":[{"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=\/wp\/v2\/posts\/569","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=569"}],"version-history":[{"count":12,"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=\/wp\/v2\/posts\/569\/revisions"}],"predecessor-version":[{"id":876,"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=\/wp\/v2\/posts\/569\/revisions\/876"}],"wp:attachment":[{"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=569"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=569"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.guguan.us.kg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=569"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}