Home > Web Front-end > JS Tutorial > Javascript implements web page shielding Backspace event, input box is not shielded_Basic knowledge

Javascript implements web page shielding Backspace event, input box is not shielded_Basic knowledge

WBOY
Release: 2016-05-16 15:49:37
Original
1140 people have browsed it

The following uses JavaScript code to block the Backspace event on the web page, and the input box is not blocked. The specific code is as follows:

document.onkeydown = function (e) { 
  var code;  
  if (!e){ var e = window.event;}  
  if (e.keyCode){ code = e.keyCode;} 
  else if (e.which){ code = e.which;} 
  //BackSpace 8; 
  if ( 
  (event.keyCode == 8) 
  && ((event.srcElement.type != "text" && event.srcElement.type != "textarea" && event.srcElement.type != "password") 
   || event.srcElement.readOnly == true 
   ) 
  ) { 
  event.keyCode = 0;   
  event.returnValue = false;  
  } 
  return true; 
}; 

Copy after login

Hope it helps everyone.

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