当前位置: 代码迷 >> JavaScript >> js 障蔽backspace键
  详细解决方案

js 障蔽backspace键

热度:97   发布时间:2012-11-09 10:18:47.0
js 屏蔽backspace键
if (typeof window.event != 'undefined') { 
           document.onkeydown = function() { 
             var type = event.srcElement.type; 
             var code = event.keyCode; 
             return ((code != 8 && code != 13) || 
                     (type == 'text' && code != 13 ) || 
                     (type == 'textarea') || 
                     (type == 'submit' && code == 13)) 
           } 
         } else { // FireFox/Others 
           document.onkeypress = function(e) { 
  
             var type = e.target.localName.toLowerCase(); 
             var code = e.keyCode; 
             if ((code != 8 && code != 13) || 
                 (type == 'input' && code != 13 ) || 
                 (type == 'textarea') || 
                 (type == 'submit' && code == 13)) { 
                 return true; 
             } else { 
                 return false ; 
             } 
           } 
         }