我想做一个计算器,显示计算前点击的数字。此版本未完成,但显示数字的代码已完成,但未按预期工作。function getHistory() { return document.querySelector(".history-value").innerText;}function printHistory(num) { document.querySelector(".history-value").innerText = num;}function getOutput() { document.getElementById("output-value").innertxt;}function printOutput(num) { document.getElementById("output-value").innerText = num;}let getOperator = document.getElementsByClassName("operator");for (var i = 0; i < getOperator.length; i++) { getOperator[i].addEventListener("click", function() { //uncompleted code })}let getNumber = document.getElementsByClassName("number");for (var i = 0; i < getNumber.length; i++) { getNumber[i].addEventListener("click", function() { let output = getOutput(); if (output != NaN) { output = output + this.id printOutput(output) } })}<div class="container"> <div class="calculator"> <div class="result"> <div class="history"> <p class="history-value"></p> </div> <div class="output"> <p id="output-value"></p> </div> </div> <div class="keyboard"> <button class="operator" id="clear">C</button> <button class="operator" id="backspace">CE</button> <button class="operator" id="%">%</button> <button class="operator" id="/">÷</button> <button class="number" id="7">7</button> <button class="number" id="8">8</button> </div> </div></div>它必须在输出中显示我按下的所有数字,但它显示未定义加上最后按下的数字
添加回答
举报
0/150
提交
取消