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

ExtJS 障蔽backspace

热度:102   发布时间:2012-11-23 22:54:33.0
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();
						}
					}
				}
			}
		});

?

  相关解决方案