English 中文(简体)
Catch Ctrl+ 进入“Ext.form.field”用户类型文本。 HtmlEditor
原标题:Catch Ctrl+Enter when the user types text in Ext.form.field.HtmlEditor

I m trying to make an Ajax request when the user presses Ctrl + Enter while entering text in Ext.form.field.HtmlEditor (xtype: htmleditor ), but I don t know how to do it.

I got a button next to the htmleditor which can send the value of the htmleditor , but I d like to add a keyboard shortcut for that operation with Ctrl + Enter.

需要用

Here is the code...

this.htmleditor = this.addComment.add({
    region:  center ,
    xtype:  htmleditor ,
    margin:  0 0 0 0 ,
    enableSourceEdit: false,
    height: 200
});
最佳回答

你们不能听听听不休的html编辑的事件。 因此,你需要使用最新的版本。

这部法典可以帮助你(参见第3号联合文件,因此也许需要修改第4版):

Cyber.ui.HtmlEditor = Ext.extend(Ext.form.HtmlEditor, {
        frame : true,
        initComponent : function() {
            Cyber.ui.HtmlEditor.superclass.initComponent.call(this);
            this.addEvents( submit );
        },
        initEditor : function() {
           Cyber.ui.HtmlEditor.superclass.initEditor.call(this);
            if (Ext.isGecko) {
                Ext.EventManager.on(this.doc,  keypress , this.fireSubmit,
                        this);
            }
            if (Ext.isIE || Ext.isWebKit || Ext.isOpera) {
                Ext.EventManager.on(this.doc,  keydown , this.fireSubmit,
                        this);
            }
        },
        fireSubmit : function(e) {
            if (e.ctrlKey && Ext.EventObject.ENTER == e.getKey()) {
                // Do what you need here
            }
        }
});

Ext.reg( customeditor , Cyber.ui.HtmlEditor);

并以你的形式:

this.htmleditor = this.addComment.add({
    region:  center ,
    xtype:  customeditor ,
    margin:  0 0 0 0 ,
    enableSourceEdit: false,
    height: 200
});

我与《Ext JS 4》进行了很多讨论,并找到了办法(在你使用html编辑之前,你需要列入这一法典):

Ext.form.HtmlEditor.override({
    frame : true,
    initComponent: function() {
        this.callOverridden();
        this.addEvents( submit );
    },

    initEditor : function() {
        this.callOverridden();

        var me = this;
        var doc = me.getDoc();

        if (Ext.isGecko) {
            Ext.EventManager.on(doc,  keypress , me.fireSubmit, me);
        }

        if (Ext.isIE || Ext.isWebKit || Ext.isOpera) {
            Ext.EventManager.on(doc,  keydown , me.fireSubmit, me);
        }
    },

    fireSubmit : function(e) {
        if (e.ctrlKey && Ext.EventObject.ENTER == e.getKey()) {
            // Do what you need here
            alert( yes! );
        }
    }
});
问题回答

> 或许是您的回馈(已经在Stack Overflow):。 Ctrl + 在TEXTAREA上使用j Query:

$( #textareaId ).keydown(function (e) {
e = e || event; // For compatibility with Internet Explorer (I believe)
  if (e.ctrlKey && e.keyCode == 13) {
    // Ctrl + Enter pressed
  }
});

这为Ext JS 6(实例使进入钥匙失效):

Ext.create( Ext.form.HtmlEditor , {
    width: 580,
    height: 250,
    renderTo: Ext.getBody(),
    listeners:{
       initialize: function(editor){
           const doc = editor.getDoc();
           const docEl = Ext.get(doc);
           docEl.on({
              keypress: (e)=>{
                if (e.event.code ===  Enter ){
                  e.preventDefault();
                }
              },
              delegated:false,
              scope: editor
           });
       }
    }
});




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签