Javascript instanceReady 事件中的 CKEditor .focus() 不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5640477/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 18:12:35  来源:igfitidea点击:

CKEditor .focus() in instanceReady event is not working

javascriptjqueryckeditor

提问by Kyaw Thurein

I am having problems in setting the focus in instanceReady event of CKEditor 3.4.1. I have already tried the following two ways but both of them are not always working.

我在 CKEditor 3.4.1 的 instanceReady 事件中设置焦点时遇到问题。我已经尝试了以下两种方法,但它们并不总是有效。

CKEDITOR.on('instanceReady', function(e) { CKEDITOR.instances.editor1.focus(); });


CKEDITOR.replace('editor1',
{
    on :
    {
        instanceReady : function( ev )
        {
            ev.editor.focus();
        }
    }
} );

回答by GianFS

or maybe try this, this is much simpler:

或者试试这个,这更简单:

use startupFocus : true

startupFocus : true

so your code should look like this:

所以你的代码应该是这样的:

CKEDITOR.replace('editor1',
{
    startupFocus : true,
...

回答by mcgrailm

here you go my friend

你去吧,我的朋友

CKEDITOR.replace('editor1',
{
    on :
    {
        instanceReady : function( ev )
        {
            CKEDITOR.instances.editor1.focus();
        }
    }
} );

or

或者

CKEDITOR.replace('editor1',
{
    on :
    {
        instanceReady : function( ev )
        {
            this.focus();
        }
    }
} );

回答by texian

CKEDITOR.instances['instance-name'].on('instanceReady', function (event) {
            CKEDITOR.instances['instance-name'].focus();
        });

回答by mikey

a bit late but:

有点晚了但是:

CKEDITOR.replace( 'YourEditor', 
{ 
 on:
   {
     instanceReady : function( evt )
     {
       //Set the focus to your editor
       CKEDITOR.instances.YourEditor.focus();
      }
    }
}

works fine for me. Found here

对我来说很好用。在这里找到

回答by Habib Ad?belli

Best way to me,

对我最好的方式,

  1. find the CKEditor instance, then
  2. trigger focus event

    The critical point is to focus instance in timeout

    for (var instance in CKEDITOR.instances) {
    $timeout(function() { CKEDITOR.instances[instance].focus(); }); }

  1. 找到 CKEditor 实例,然后
  2. 触发焦点事件

    关键点是在超时时关注实例

    for (CKEDITOR.instances 中的 var 实例) {
    $timeout(function() { CKEDITOR.instances[instance].focus(); }); }

Note: I found the instance with a for loop. You may find better way to find the instance

注意:我找到了带有 for 循环的实例。您可能会找到更好的方法来查找实例

回答by Saquibul Islam Waheed

Neither of the above answers worked for me. Here is what I did for CHROMEand it works just fine:

以上答案都不适合我。这是我为CHROME所做的,它工作得很好:

CKEDITOR.instances['instance-name'].container.focus();

回答by Saquibul Islam Waheed

Dirty way (Make sure you read the comment under my answer):

肮脏的方式(请确保您阅读了我的答案下的评论):

jQuery('.cke_wysiwyg_frame').contents().find('body').focus();