zoukankan      html  css  js  c++  java
  • 禁止浏览器backspace键(退格键)时跳转页面(extjs,javascript)

    Ext实现方式:

    //方法一
     var key = new Ext.KeyMap(document,{
      key: 8,
      fn: function(obj,e){
       var type = e.target.type;
       var readonly = e.target.readOnly;
       if(type != 'text' && type != 'textarea' && type != 'password'){
        //e.preventDefault();
        e.stopEvent();
       }
       else if(readonly){
        //e.preventDefault();
        e.stopEvent();
       }
      },
      scope: this
     });
    //方法二
    
    
    
    Ext.getDoc().on('keydown',function(e){  
        if(e.getKey() == 8 && e.getTarget().type =='text' && !e.getTarget().readOnly){  
              
        }else if(e.getKey() == 8 && e.getTarget().type =='textarea' && !e.getTarget().readOnly){   
          
        }else if(e.getKey() == 8){  
            e.preventDefault();  
        }  
    }); 

    JavaScript实现方式:

    function document.onkeydown()   
    {   
      if ((event.keyCode==8) ) //屏蔽退格删除键  
      {   
        if (window.event.srcElement.tagName.toUpperCase()!="INPUT" && window.event.srcElement.tagName.toUpperCase()!="TEXTAREA" && window.event.srcElement.tagName.toUpperCase()!="TEXT")  
        {  
          event.keyCode=0;   
          event.returnValue=false;  
        }   
      }   
    }  
  • 相关阅读:
    Codeforces 1354C2
    Codeforces 1354C1
    Codeforces 1355C
    Codeforces 1353D
    Codeforces 1352
    Codeforces 1351C
    Codeforces 1344B/1345D
    Codeforces 1342D
    Codeforces 1340B/1341D
    Codeforces 1343D
  • 原文地址:https://www.cnblogs.com/mingforyou/p/3930673.html
Copyright © 2011-2022 走看看