Cómo deshabilitar el retroceso excepto el cuadro de texto usando jQuery
Frecuentes
Visto 2,371 veces
-4
I want to disable BACKSPACE button except when its in TEXT field.
I am using following code but it prevent backspace functionality include text field.. BACKSPACE should work for TEXT field only..
Please help this out...
$(document).on("keydown", processKeyEvents);
$(document).on("keypress", processKeyEvents);
function processKeyEvents(event) {
// Backspace
if (event.keyCode == 9) {
// myTextBox is id of the valid textbox
if ($("*:focus") != $("#myTextBox")) {
event.preventDefault();
}
}
}
2 Respuestas
1
Check keydown events and if backspace
is pressed preventdefault if a textarea is not focused.
http://jsfiddle.net/Q9Meh/2/
$('body').keydown(function(event) {
if (event.which == 8 && !$('textarea:focus').length) {
event.preventDefault();
}
});
Respondido el 23 de diciembre de 12 a las 15:12
0
¿Qué tal esto? myTextBox
is the id of your textbox in which backspace should work.
$(document).on("keydown", processKeyEvents);
$(document).on("keypress", processKeyEvents);
function processKeyEvents(event) {
// Backspace
if (event.keyCode == 8) {
// myTextBox is id of the valid textbox
if ($("*:focus") != $("#myTextBox")) {
event.preventDefault();
}
}
}
Respondido el 24 de diciembre de 12 a las 04:12
Hi Friends, Thanks for your responses but It didnt met my requirementas of now. Actually I want to disable Backspace buttnon(keyboard button) always. but when text get focus should be enable. - PAM
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas jquery html or haz tu propia pregunta.
I imported the content of your duplicate post: stackoverflow.com/questions/14017224/… - Wesley Murch