简体   繁体   English

tinyMCE textarea聚焦事件?

[英]tinyMCE textarea focusout event?

I am working on existing project. 我正在处理现有项目。 I have to detect tinyMCE focusout/blur event to save it automatically via AJAX. 我必须检测tinyMCE focusout/blur事件以通过AJAX自动保存它。 I found following existing working code: 我发现以下现有工作代码:

// reinit tinymce
$($("#chapterBill div:.module-container")[indexAfter]).find('textarea').each(function(i){
   editorId = $(this).attr('id');
   tinymce.EditorManager.execCommand('mceAddControl',true, editorId);
});

Can someone tell me that how to capture tinyMCE textarea focusout/blur event ? 有人可以告诉我如何捕获tinyMCE textarea focusout/blur事件吗?

Thanks 谢谢

You do not want to capture textarea focus/blur. 您不想捕获文本区域的焦点/模糊。 Tinymce hides the former textarea and creates a contenteditable iframe in which you can enter/edit content. Tinymce隐藏了以前的文本区域,并创建了一个可编辑内容的iframe,您可以在其中输入/编辑内容。 This content gets written to the former hidden textarea from time to time (eventbased). 有时会将此内容写入以前的隐藏文本区域(基于事件)。

In order to capture focusout/blur on the editor you need to set a handler for this on the editors iframe. 为了在编辑器上捕获聚焦/模糊,您需要在编辑器iframe上为此设置一个处理程序。

Put this code into your tinymce init 将此代码放入您的tinymce init

setup : function(ed) {
    ed.onInit.add(function(ed, evt) {
        tinymce.dom.Event.add(ed.getDoc(), 'blur', function(e) {
            // Do something when the editor window is blured.
            alert('blur!!!');
        });
    });
},

I too was working on a solution in order to save tinyMCE content dynamically via AJAX. 我也正在研究一种解决方案,以便通过AJAX动态保存tinyMCE内容。 Many answers instruct to set this option in the init, however this convenience was not available to me, due to the fact that the code was being used across several systems. 许多答案指示在init中设置此选项,但是由于该代码已在多个系统上使用,因此我不方便使用此选项。 I required a page specific solution, which I was able to implement like so: 我需要一个特定于页面的解决方案,该解决方案能够像这样实现:

$( window ).load(function(){
    tinymce.get('id').on('blur', function(e) {
        var content = tinymce.get('id');
        console.log(content);
    });
});

With id being the id attribute set on your textarea element. id是在textarea元素上设置的id属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM