禁止backspace键(退格键),但输入文本框时不禁止(兼容IE)
Ext实现方式:
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(); } });JS实现方式:
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; } } }
原文:http://www.cnblogs.com/kristain/articles/2106140.html

浙公网安备 33010602011771号