如何重置事件?
我正在构建一个计算器。我无法显示用户要计算的第二个数字。例如,如果用户想计算10 * 2。我想显示10。单击 *后,我想存储10次以供以后使用,并显示2。
//select screen display element
let screen = document.querySelector(".screen");
//select all calculator number keys
let numberKeys = document.querySelectorAll(".keys");
//select operator elements
let operators = document.querySelectorAll(".operators");
numberKeys.forEach((key) => {
key.addEventListener("click", (e) => {
screen.innerText += e.target.innerText;
});
});
operators.forEach((op) => {
op.addEventListener("click", (e) => {
screenValue += screen.innerText;
operator = e.target.innerText;
secondNumber += screen.innerText;
});
});
I'm building a calculator. I can't get it to display the 2nd number that the user wants to calculate. For example, if the user wants to calculate 10 * 2. I want to display the 10. After they click *, I want to store 10 for later use, and display the 2.
//select screen display element
let screen = document.querySelector(".screen");
//select all calculator number keys
let numberKeys = document.querySelectorAll(".keys");
//select operator elements
let operators = document.querySelectorAll(".operators");
numberKeys.forEach((key) => {
key.addEventListener("click", (e) => {
screen.innerText += e.target.innerText;
});
});
operators.forEach((op) => {
op.addEventListener("click", (e) => {
screenValue += screen.innerText;
operator = e.target.innerText;
secondNumber += screen.innerText;
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论