javascript tinyMCE 模糊事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5593019/
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-10-25 17:42:29  来源:igfitidea点击:

tinyMCE blur event

javascriptjquerytinymceonblurrte

提问by T1000

Hello I want to do some stuff when user finished writing in the tinyMCE textarea and click somewhere outside (onBlur). So far I haver try:

您好,当用户在 tinyMCE 文本区域中完成书写并单击外部某处 (onBlur) 时,我想做一些事情。到目前为止,我已经尝试过:

$('#id_topic_text_parent').live('blur',function(){
    alert('asd')
//I saw #id_topic_text_parent in firebug, it is span containing the tiny mce
});

also

$('#id_topic_title').blur(*and*)live('blur...
tinyMCE.activeEditor.blur(*and*)live('blur...

But it wont work.
Can you assist me.

但它不会工作。
你能帮我吗。

回答by ptguy

according to http://www.tinymce.com/wiki.php/api4:event.tinymce.Editor.blur

根据http://www.tinymce.com/wiki.php/api4:event.tinymce.Editor.blur

This works for me

这对我有用

setup : function(ed) {
    ed.on('blur', function(e) {
        alert('blur');
    });
},

回答by Thariama

You can use this approach to solve your issue. When initializing tinymce set the setup paramter to the following (inside tinyMCE.init({...})

您可以使用这种方法来解决您的问题。初始化 tinymce 时将 setup 参数设置为以下(内部tinyMCE.init({...})

...
theme: "advanced",   // example param
plugins = 'code',    // example param
setup : function(ed) {
    ed.onInit.add(function(ed, evt) {

        var dom = ed.dom;
        var doc = ed.getDoc();

        tinymce.dom.Event.add(doc, 'blur', function(e) {
            // Do something when the editor window is blured.
            alert('blur!!!');
        });
    });
},
cleanup: true,      // example param
...

回答by Mudaser Ali

Please use

请用

function myCustomOnChangeHandler(inst) {
        alert("Some one modified something");
        alert("The HTML is now:" + inst.getBody().innerHTML);
}

tinyMCE.init({
        ...
        onchange_callback : "myCustomOnChangeHandler"
});

Ref: http://www.tinymce.com/wiki.php/Configuration:onchange_callback

参考:http://www.tinymce.com/wiki.php/Configuration: onchange_callback

This function is called once the user "blurs" the area;

一旦用户“模糊”该区域,就会调用此函数;

回答by FrancescoMM

I used this to close the external toolbar on blur, it seemsto work (tested only on FF at the moment)

我用它来关闭模糊的外部工具栏,它似乎有效(目前仅在 FF 上测试)

function showHideBar(sho,aid) { // aid=id not used
    if(sho) {
        $( ".mceToolbar,.mceExternalClose" ).show();
    } else {
        $( ".mceToolbar,.mceExternalClose" ).hide();
    }
}

tinyMCE.init({

    // ....

    theme_advanced_toolbar_location: "external",
    resize : true,
    setup : function(ed) {
        ed.onInit.add(function(ed, event) {
            $(ed.getBody()).blur(function() {
                // alert("blur");
                showHideBar(false,ed.id);
            });

            $(ed.getBody()).focus(function() {
                // alert("focus");
                showHideBar(true,ed.id);
            });

        });
    },

    // ....

}

回答by Calum

Edit:

编辑:

$('#id_topic_text_parent textarea').live('blur', function() {
   alert('asd');
});

Can you post the html for the #id_topic_text_parent span?

您可以发布 #id_topic_text_parent 跨度的 html 吗?

$('#id_topic_text_parent').find('textarea').blur(function(){ alert('asd'); });

$('#id_topic_text_parent').find('textarea').blur(function(){ alert('asd'); });

回答by Dmitry Kulahin

Let's say you have textarea:

假设您有 textarea:

<textarea id="mytext">

And you initialized TinyMCE editor:

你初始化了 TinyMCE 编辑器:

tinymce.init({
    selector: '#mytext',
    // ...
});

You can bind "onblur" event using such code:

您可以使用以下代码绑定“onblur”事件:

tinyMCE.get('mytext').on('blur', function(e) {
    console.log(this); // "this" contains tinymce.Editor object
});

Reference and details: https://www.tiny.cloud/docs/api/tinymce/tinymce.focusevent/

参考及详情:https: //www.tiny.cloud/docs/api/tinymce/tinymce.focusevent/