【问题标题】:How to Insert text at the cursor position at a particular ckeditor?如何在特定ckeditor的光标位置插入文本?
【发布时间】:2019-03-23 08:16:53
【问题描述】:

我添加了一个自定义插件,当我单击不属于 ckeditor 工具栏按钮的 InsertDate 按钮时,该插件会在 ckeditor 的光标位置插入当前日期。现在的问题是我的页面中有多个 ckeditor,所以现在我在第二个 ckeditor 中输入一些内容,我只想插入当前时间,所以我点击了 insertDate 按钮,但它在第一个 ckeditor 中插入了文本不是预期的。有什么方法可以处理这种情况。我想知道最近关注的 ckeditor,以便我可以使用 id 识别特定的 ckeditor 并插入文本。

尝试使用 focusmanager.hasfocus 方法,但是一旦我单击 insertDate 按钮,ckeditor 就会失去焦点。有什么方法可以获取最近焦点编辑器的参考。

【问题讨论】:

  • 查看官方插件教程了解类似内容:ckeditor.com/docs/ckeditor4/latest/guide/plugin_sdk_sample.html
  • 不,它不起作用。这个例子只是展示了如何创建一个基本插件来在 ckeditor 中插入时间和日期。但在我的情况下,我有两个 ckeditor
  • 每个插件仅在其 CKEditor 实例中起作用。所以,如果你实现了timestamp插件,你会看到如果你点击timestamp工具栏按钮,当前的timestamp只会插入到这个按钮的CKEditor实例中,而不会插入到其他实例中。

标签: ckeditor ckeditor4.x


【解决方案1】:
$.fn.insertAtCaret = function (myValue) {
    myValue = myValue.trim();
    CKEDITOR.instances['idofeditor'].insertText(myValue);
};

【讨论】:

    猜你喜欢
    • 2012-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多