문제

The following code works. It allows you to press the enter and escape buttons. Here is a 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
    }
});

My question is how would I remove the binding for just the enter key?

도움이 되었습니까?

해결책

e.preventDefault(), and return false; in the function

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

or if you mean just the event binding

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

if you mean just for that particular binding you can set a namespace

$(document).on('keydown.mykeydown'...
$(document).off('keydown.mykeydown');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top