Disable all keys with jQuery except backspace - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:keydown

Description

Disable all keys with jQuery except backspace

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://code.jquery.com/jquery-git.js"></script> 
      <script type="text/javascript">
    $(function(){//from  w  w w  . j  a  v  a 2  s  .c o  m
$('#text').keydown(function(e) {
    if(e.keyCode !== 8) {
        e.preventDefault();
    }
});
    });

      </script> 
   </head> 
   <body> 
      <input type="text" id="text" value="You can only backspace!">  
   </body>
</html>

Related Tutorials