I need to make the letter f only work in text fields, in other places it does not work, eg:
$(document).keyup(function(e) {
if (e.keyCode == 37) {
return false;
}
});
I need to make the letter f only work in text fields, in other places it does not work, eg:
$(document).keyup(function(e) {
if (e.keyCode == 37) {
return false;
}
});
For this, you only need to prevent propagation from the event in the text fields - so that the generic code does not act on it. In addition, it is best to treat keydown
instead of keyup
because - when keyup
is activated - the effect of pressing the key has already happened.
$(document).keydown(function(e) {
if (e.keyCode == 70) {
return false; // Equivalente a: e.stopPropagation(); e.preventDefault();
}
});
$('input[type="text"]').keydown(function(e) {
e.stopPropagation();
});