1

以下代码有效。它允许您按下进入和退出按钮。这是一个jsFiddle

$(document).on('keydown', function(e){
    if (e.which == 13){
        // Enter Key pressed
    }
});
$(document).on('keydown', function(e){
    if (e.which == 27){
        // Esc Key pressed
    }
});

我的问题是如何删除仅输入键的绑定?

4

1 回答 1

2

e.preventDefault(),并返回 false;在函数中

$(document).on('keydown', function(e){
    if (e.which == 13){
        e.preventDefault();
        return false;
    }
});

或者如果你的意思只是事件绑定

$(document).off('keydown');

如果您的意思只是针对该特定绑定,您可以设置命名空间

$(document).on('keydown.mykeydown'...
$(document).off('keydown.mykeydown');
于 2013-06-30T14:32:17.533 回答