-1
    function addone()
    {
            document.getElementById("subtract").disabled=false;
    x += 1;
    document.getElementById("result").innerHTML="Doshi has said OK " + x + " times."
if(x == 1 ){
    document.getElementById("resetall").disabled=false;
    document.getElementById("reset").disabled=false;
    document.getElementById("result").innerHTML="Doshi has said OK " + x + " time."
}
if(x == 0){
    document.getElementById("resetall").disabled=true;
    document.getElementById("reset").disabled=true;
    document.getElementById("result").innerHTML="Doshi has not said OK "
}
    }

当我按下“1”键时,我想启动这个功能。我该怎么做呢

4

1 回答 1

3
window.onkeypress = function(event) {
   if (event.keyCode == 41) {
      // do a function
   }
}

而不是 onkeypress 你可以看看 onkeydown / onkeyup

字符代码列表:http ://www.asciitable.com/

于 2013-02-06T17:32:11.003 回答