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

ExtJS 屏蔽backspace
/**
 * @author wangsr
 * @date 2012-09-06
 * 键盘事件管理
 */
Ext.define("Gboat2.desktop.util.KeyManager", {
			alternateClassName : "GKeyManager",
			singleton : true,

			maskBackspace : function() {
				var DOC = Ext.getDoc();
				DOC.on({
							'keydown' : maskBS,
							'keyup' : maskBS
						});
				function maskBS(event, targetHtml) {
					var keycode = event.getKey();
					var obj = targetHtml;
					if (keycode == Ext.EventObject.BACKSPACE) {
						if (obj != null && obj.tagName != null
								&& (obj.tagName.toLowerCase() == "input" || obj.tagName.toLowerCase() == "textarea")) {
							//readOnly
							var fieldEl, fieldCmp;
							fieldEl = Ext.get(obj).up('table.x-form-item');
							if (fieldEl && fieldEl.id) {
								fieldCmp = Ext.getCmp(fieldEl.id);
							}
							if (fieldCmp && fieldCmp.readOnly) {
								event.stopEvent();
							}
						} else {
							event.stopEvent();
						}
					}
				}
			}
		});

?