TinyMCE - 检查文本是否被选中

TinyMCE - Check if the text is selected

我尝试查看 TinyMCE 内联编辑器当前是否可见或文本是否被选中。


已解决。
Christoffer 指导我做了正确的事情:

 <script>
  tinymce.init({
    selector:"textarea",
    setup: function(editor) {
      editor.on('focus', function() {
        console.log('focus');
      });
      editor.on('blur', function(){
        console.log('blur');
      })
    }
  });
</script>

更多信息在这里: Why TinyMCE get focus and blur event, when user jump from other input field?

您可以通过以下方式从活动编辑器中获取当前选择:

tinyMCE.activeEditor.selection.getContent();

您还可以使用以下内容循环所有编辑器:

for (edId in tinymce.editors) {
    if (tinymce.editors[edId].isDirty()) {
        // do stuff
    }
}

要更高级地控制编辑器何时以及是否处于活动状态,您可以在编辑器初始化中设置对 init/focus 和模糊事件的回调。