gpt4 book ai didi

javascript - 获取评估后的答案以在显示屏上阅读

转载 作者:行者123 更新时间:2023-11-28 01:47:43 25 4
gpt4 key购买 nike

只是想知道是否有人可以建议如何在这段 JS 的末尾获取评估的答案,以便在我创建的显示 ID 上读取?

function setup() {
var i;
for (i = 0; i <= 9; i++) {
document.getElementById(i).onclick = handleInput;
document.getElementById("operator_*").onclick = handleInput;
document.getElementById("operator_/").onclick = handleInput;
document.getElementById("operator_.").onclick = handleInput;
document.getElementById("operator_-").onclick = handleInput;
document.getElementById("operator_+").onclick = handleInput;

var x;
document.getElementById("operator_=").onclick = evaluateInput;

}

}

function handleInput(e) {
var s = document.getElementById("display").childNodes[0];
s.nodeValue += e.srcElement.childNodes[0].nodeValue ;
console.log(e.srcElement.id);

}

function evaluateInput(e) {
console.log(eval(document.getElementById("display").childNodes[0].nodeValue));

}

非常感谢...

最佳答案

Do you have any advice for the issue at hand?

事实上,我也这么认为:)

DEMO

function setup() {
var i;
for (i = 0; i <= 9; i++) {
document.getElementById(i).onclick = handleInput;
document.getElementById("operator_*").onclick = handleInput;
document.getElementById("operator_/").onclick = handleInput;
document.getElementById("operator_.").onclick = handleInput;
document.getElementById("operator_-").onclick = handleInput;
document.getElementById("operator_+").onclick = handleInput;

//var x;
document.getElementById("operator_=").onclick = evaluateInput;
}
}

function handleInput(e) {
var s = document.getElementById("display");
s.innerHTML += e.srcElement.childNodes[0].nodeValue;
}

function evaluateInput(e) {
var s = document.getElementById("display");
s.innerHTML = eval(document.getElementById("display").childNodes[0].nodeValue);
}

setup();

关于javascript - 获取评估后的答案以在显示屏上阅读,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20080849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com