Disable certain key's default action

前端 未结 1 1477
情书的邮戳
情书的邮戳 2020-12-09 14:40
function keypressCheck() {
    var keyID = event.keyCode;

    //space pressed
    if (keyID == 32) {
        anotherFunction();
    }
}

I want

相关标签:
1条回答
  • 2020-12-09 14:49

    It should work. Just to make sure, try this:

    function keypressCheck(e) { 
        var e = window.event||e; // Handle browser compatibility
        var keyID = e.keyCode;
        //space pressed
        if (keyID == 32) {
            e.preventDefault(); // Prevent the default action
            anotherFunction();
        }
    }
    
    0 讨论(0)
提交回复
热议问题