Home > Web Front-end > JS Tutorial > 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
Release: 2016-05-16 16:14:13
Original
1298 people have browsed it

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.
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template