日期:2014-05-19  浏览次数:20747 次

Extjs中设置快捷键的问题,弄了两天了还是没弄出来。郁闷。。。
有个设置快捷键的问题我弄了两天了还是没弄出来。郁闷。。。
 
 
要给Extjs 中的htmleditor设置快捷键,当按键盘的enter键或者什么键就可以执行某种操作。我试了好多方法,,,keymap都貌似不起作用。


谁有做过这方面的东西没有?

------解决方案--------------------
Ext也不太懂,试试下面代码:
JScript code

htmleditor.listeners = {keyup: function(ee, keyEvent){
                if(keyEvent.getKey() == 13){
                    alert("Enter Key!!");
                }
            }};

------解决方案--------------------
ext 在Eclipse有个插件 还不错 sp开头的 确实忘了 瓢虫样子的图表
比htmleditor 强太多了

------解决方案--------------------
JScript code
/***
 * 重写Ext.form.HtmlEditor,为其添加键盘事件
 * author: hoojo
 * email: hoojo_@126.com
 * blog: http://blog.csdn.net/IBM_hoojo
 * create by: 2010-8-14
 * ext-lib: 3.2.1
 * version: 1.0
 */
Ext.override(Ext.form.HtmlEditor, {
    initEditor : function(){
        var dbody = this.getEditorBody();
        var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
        ss['background-attachment'] = 'fixed'; // w3c
        ss['background-color'] = 'white';
        dbody.bgProperties = 'fixed'; // ie
        Ext.DomHelper.applyStyles(dbody, ss);
        if(this.doc){
            try{
                Ext.EventManager.removeAll(this.doc);
            }catch(e){}
        }
        this.doc = this.getDoc();
        Ext.EventManager.on(this.doc, {
            'mousedown': this.onEditorEvent,
            'dblclick': this.onEditorEvent,
            'click': this.onEditorEvent,
            'keyup': this.onEditorKeyUpEvent,
            'keydown': this.onEditorKeyDownEvent,
            'keypress': this.onEditorKeyPressEvent,
            buffer:100,
            scope: this
        });
        if(Ext.isGecko){
            Ext.EventManager.on(this.doc, 'keypress', this.applyCommand, this);
        }
        if(Ext.isIE || Ext.isSafari || Ext.isOpera){
            Ext.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
        }
        this.initialized = true;
        this.fireEvent('initialize', this);
        this.doc.editorInitialized = true;
        this.pushValue();
    },
    initComponent: function () {
        this.addEvents(
            'initialize',
            'activate',
            'beforesync',
            'beforepush',
            'sync',
            'push',
            'editmodechange',
            'keydown',
            'keyup',
            'keypress'
        );
    },
    onEditorKeyPressEvent : function(e){
        this.updateToolbar();
        this.fireEvent("keypress", this, e);
    },
    onEditorKeyUpEvent : function(e){
        this.updateToolbar();
        this.fireEvent("keyup", this, e);
    },
    onEditorKeyDownEvent : function(e){
        this.updateToolbar();
        this.fireEvent("keydown", this, e);
    }
});
在js中加入这段代码应该就可以了

------解决方案--------------------
不用那个复杂的东西。 直接自己用js写一段。 复杂的嘛 咱不会