创建显示的重置按钮

时间:2013-11-19 21:46:20

标签: javascript button reset clear

我想知道是否有人能够帮助创建一个可以重置我的显示器的按钮?我选择将其作为派生自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;
}

谢谢!

1 个答案:

答案 0 :(得分:1)

我们再见面......

DEMO

document.getElementById("c").onclick = clearInput;

...

function clearInput(e) {
    var s = document.getElementById("display");
    s.innerHTML = null;
}