现在,我正在使用这行代码来禁用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>
您是否尝试过设置
readonly
配置参数?根据 TinyMCE 文档(http://www.tinymce.com/wiki.php/Configuration3x:readonly):
此选项使您能够以只读模式指定 make 编辑器实例。当它们处于只读模式时,无法更改任何内容,内容仅呈现给用户。您可以将其与 body_class 结合使用,为只读模式呈现不同的视觉呈现。
因此,您可以添加类似的内容(来自同一来源):
// Move focus to specific element
tinyMCE.init({
...
theme : "advanced",
readonly : 1
});
在 V6 中:
tinymce.activeEditor.hide()
然后再次打开它
tinymce.activeEditor.show()
https://www.tiny.cloud/docs/tinymce/6/apis/tinymce.editor/#hide