Home  >  Article  >  Web Front-end  >  JQuery implements a method to prevent the backspace key from returning_jquery

JQuery implements a method to prevent the backspace key from returning_jquery

WBOY
WBOYOriginal
2016-05-16 16:14:131276browse

The example in this article describes how JQuery prevents the backspace key from returning. Share it with everyone for your reference. The specific implementation method is as follows:

Copy code The code is as follows:
//Backspace is not available in the browser
$(document).keydown(function(e){
var keyEvent;
If(e.keyCode==8){
              var d=e.srcElement||e.target;                                  If(d.tagName.toUpperCase()=='INPUT'||d.tagName.toUpperCase()=='TEXTAREA'){
                      keyEvent=d.readOnly||d.disabled;                                                                                                                                                                            keyEvent=true;                                                                                                                                                                                                                                 keyEvent=false;                                                                                                                       If(keyEvent){
               e.preventDefault();                                                                                                                 });

//Only prevent input and textarea. Backspace is still available in the browser
$(document).keydown(function(e){
var keyEvent;
if(e.keyCode==8){
var d=e.srcElement||e.target;
If(d.tagName.toUpperCase()=='INPUT'||d.tagName.toUpperCase()=='TEXTAREA'){
                      keyEvent=d.readOnly||d.disabled;                                                                                                                                                                                 } else{
               keyEvent=false; 
}
if(keyEvent){
               e.preventDefault();                                                                                                                 });


I hope this article will be helpful to everyone’s jQuery programming.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn