我想知道是否有人能够帮助创建一个可以重置我的显示器的按钮?我选择将其作为派生自onclick的函数包含在内:
function setup() {
var i;
for (i = 0; i <= 9; i++) {
document.getElementById(i).onclick = handleInput;
document.getElementById("*").onclick = handleInput;
document.getElementById("/").onclick = handleInput;
document.getElementById(".").onclick = handleInput;
document.getElementById("-").onclick = handleInput;
document.getElementById("+").onclick = handleInput;
var evaluate;
document.getElementById("=").onclick = evaluateInput;
var clear;
document.getElementById("c").onclick = clearInput;
value = "reset"
}
}
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) {
var s = document.getElementById("display");
s.innerHTML = eval(document.getElementById("display").childNodes[0].nodeValue);
}
function clearInput() {
document.getElementById("display").childNodes[0].selectedIndex = 0;
}
谢谢!
答案 0 :(得分:1)
我们再见面......
document.getElementById("c").onclick = clearInput;
...
function clearInput(e) {
var s = document.getElementById("display");
s.innerHTML = null;
}