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

解决方案 »

  1.   

    Ext也不太懂,试试下面代码:htmleditor.listeners = {keyup: function(ee, keyEvent){
                    if(keyEvent.getKey() == 13){
                        alert("Enter Key!!");
                    }
                }};
      

  2.   

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

  3.   

    /***
     * 重写Ext.form.HtmlEditor,为其添加键盘事件
     * author: hoojo
     * email: [email protected]
     * 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中加入这段代码应该就可以了
      

  4.   

    我的代码是这么写的。
    new Ext.Panel( {
    region:'south',
    layout:'fit',
    items:{
    xtype:'htmleditor',
    name :'content',
    id:'content',
    listeners:{
       'render' : function(editor){
             var ifameDom = editor.getEl().dom.nextSibling.contentWindow;
             if(ifameDom){
             if (window.attachEvent){
               alert(1);
                 ifameDom.document.attachEvent('onkeyup',function(e){
                 if(e.ctrlKey && e.keyCode == 13){
                 alert("1:"+1313);
                 }
                 })                                                                              
              }else{
              ifameDom.addEventListener('keyup', function(e){
               if(e.ctrlKey && e.keyCode == 13){
                     alert("2:"+1313);  
                  }                                                                    
               }, false);                                                                                    
      }
      }
      }
    }
    }
    })  new Ext.Panel( {
    layout:'fit',
    items:{
    xtype:'htmleditor',
    name :'content',
    id:'content'
    }
     }), 上面就是我的代码, ifameDom.document.attachEvent('onkeyup',function(e){}关于键盘的这个事件没有运行了。
      

  5.   

    谢谢大家啊!特别感谢IBM_hoojo。
    现在又有两个新问题请教了。1.在window加载完成后给htmleditor聚焦为什么不行。
    我的代码是这么写的。
    var htmleditor=Ext.getCmp("htmleditor");
    if(htmleditor.isVisible()==true)
    {
      htmleditor.focus(true);
    }
     
    2.window加载htmleditor后,为什么有时候htmleditor是处于可编辑状态有时候加载完成是不可编辑的,不可编辑时必须要点一下字体选择的下拉框才可以在里面输入内容。这是什么问题???跟IE有关还是它本身的bug。