Using jquery to implement IE backspace is equivalent to a return operation

  • 2020-03-30 02:25:53
  • OfStack

In fact, disable is not completely disabled, the back button in each browser is the default click on the back button, as long as the guarantee of normal text input can also be used, under other circumstances backspace key will be banned. Take a look at the jquery implementation code:
 
$(function(){ 
function dokey(event){ 
var ele = event.target; 
var eleName = ele.nodeName; 
var flag = true; 
if(eleName=="INPUT"||eleName=="TEXTAREA"||eleName=="SELECT"){ 
var re = $(ele).attr("readonly"); 
if(re){ 
flag = true; 
}else{ 
flag = false; 
} 
} 
if(event.which==8&&flag){ 
event.preventDefault(); 
event.stopPropagation(); 
} 
} 
$(document).keypress(dokey).keydown(dokey); 
}); 

Related articles: