Advertisement
Guest User

Backspace fix

a guest
Aug 28th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(function () {
  2.     var rx = /INPUT|TEXTAREA/i;
  3.     var rxT = /RADIO|CHECKBOX|SUBMIT|BUTTON/i;
  4.    
  5.     $(document).bind("keydown keypress", function (e) {
  6.         var preventKeyPress = e.keyCode - 0 === 8;
  7.  
  8.         if (preventKeyPress && rx.test(e.target.tagName)) {
  9.             var d = e.srcElement || e.target;
  10.             preventKeyPress = d.readOnly || d.disabled || (d.attributes.type ? rxT.test(d.attributes.type.value) : false);
  11.         }
  12.    
  13.         if (preventKeyPress) { e.preventDefault(); }
  14.     });
  15.    
  16. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement