【问题标题】:How to configure TinyMCE editor event to be fired only once?如何将 TinyMCE 编辑器事件配置为仅触发一次?
【发布时间】:2019-01-29 13:20:28
【问题描述】:

我要求只触发一次“SetContent”事件。我试过了

var ed = tinymce.get("editor");
ed.on('SetContent', function(e) {
    // Turns off event so that it doesn't fire again
    ed.off('SetContent');
    //  Performs the task that need to be performed once
});
ed.setContent('some content');

我使用的是 TinyMCE 版本:4.9.2-120

上面的代码引发了一个 JavaScript 错误并且不起作用。

TinyMCE 网站上有一个链接说这是可行的 http://archive.tinymce.com/wiki.php/api4:method.tinymce.off.static

有人可以指导我吗?

谢谢。

【问题讨论】:

    标签: javascript tinymce tinymce-4


    【解决方案1】:

    您好,我已经解决了这个问题。

    基本上,有一个功能可以让您只运行一次事件。像这样使用它:

    var ed = tinymce.get("editor");
    ed.once('SetContent', function(e) {
        //  Performs the task that need to be performed once
    });
    ed.setContent('some content');
    

    我希望这对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-21
      • 2023-03-21
      • 2020-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多