日期:2014-05-16  浏览次数:20339 次

【抄】JS屏蔽Enter键和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 ;  
            }  
          }  
        }