【问题标题】:How to disable tinymce after it is fully initialized?完全初始化后如何禁用tinymce?
【发布时间】:2014-10-20 16:00:04
【问题描述】:

现在,我正在使用这行代码来禁用 tinyMCE

tinyMCE.get('tinymce_id').getBody().setAttribute('contenteditable', false);

但是,它似乎并没有在初始化时被禁用。只有当我选择单选按钮时,它才会被禁用。

如何在初始化后禁用特定的 tinyMCE 编辑器?如果可能的话,我想要一个也适用于 IE8 的答案。提前致谢!


jQuery :

 require(['tinymce'],function(){

            var disableInputs = function(){
                if($('input[name=type]:checked').val()==1){
                    tinyMCE.get('newsletter_message').getBody().setAttribute('contenteditable', false);
                    tinyMCE.get('category_message').getBody().setAttribute('contenteditable', true);
                }else{
                    tinyMCE.get('newsletter_message').getBody().setAttribute('contenteditable', true);
                    tinyMCE.get('category_message').getBody().setAttribute('contenteditable', false);
                }
            };
            $('input[name=type]').on('click',function(){
                disableInputs();
            });
            disableInputs();

        });

HTML:

<input type="radio" value=1 name=type/>
<div id="newsletter"> tinymce with id of newsletter_message initializes here... </div>

<input type="radio" value=0 name=type/>
<div id="category"> tinymce with id of category_message initializes here... </div>

【问题讨论】:

  • tinyMCE.remove(); ?
  • @KevinLabécot 你确定吗?我不想删除它。只想禁用它。
  • 好吧,好吧。我错了;)

标签: javascript jquery html tinymce


【解决方案1】:

您是否尝试过设置readonly 配置参数?根据 TinyMCE 文档 (http://www.tinymce.com/wiki.php/Configuration3x:readonly):

此选项使您可以在只读模式下指定 make 编辑器实例。当它们处于只读模式时,无法更改任何内容,并且内容只是呈现给用户。您可以将它与 body_class 结合使用,为只读模式呈现不同的视觉呈现。

因此,您可以添加类似(来自同一来源)的内容:

// Move focus to specific element
tinyMCE.init({
        ...
        theme : "advanced",
        readonly : 1
});

【讨论】:

    猜你喜欢
    • 2013-09-02
    • 2015-02-17
    • 2018-12-27
    • 1970-01-01
    • 2014-12-28
    • 2021-09-07
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多