我需要在运行时禁用或使tinymce文本区域只读。
从4.3.x版本开始,您可以使用以下代码来进入只读模式
tinymce.activeEditor.setMode('readonly');
并且对于设计模式:
tinymce.activeEditor.setMode('design');
tinyMCE.get('editor_ID').setMode('readonly');
来使编辑器只读。 - Стас Пишевский如果你只有一个编辑器,这个方法可以使用:
tinymce.activeEditor.getBody().setAttribute('contenteditable', false);
如果您有多个编辑器,您需要通过文本区域的ID进行选择:tinyMCE.get('textarea_id').getBody().setAttribute('contenteditable', false);
<Editor
initialValue={details}
disabled = {true}
init = {{
height: 300,
menubar: false,
toolbar: false,
readonly: true
}}/>
readonly
被覆盖的情况:https://www.tiny.cloud/docs/integrations/react/#init - cyclingLinguist如果您想禁用它,可以调用此命令:
tinymce.EditorManager.execCommand('mceToggleEditor', true, tinymceId);
要重新启用编辑器,您可以再次调用此命令。
'mceToggleEditor' 命令通过显示或隐藏文本区域和编辑器实例来切换所见即所得模式的开启或关闭。这与 mceAddControl 或 mceRemoveControl 不同,因为实例仍然存在但未初始化,所以此方法更快。
上述命令的链接: http://archive.tinymce.com/wiki.php/TinyMCE3x:Command_identifiers
对于最新的5.x版本,请使用
editor.mode.set('readonly')
并且
editor.mode.set('design')
您可以通过 @rioted 的答案 https://dev59.com/xG445IYBdhLWcg3w4-Be#34764607 在此处查看。
我使用它来得出这个解决方案:
tinymce.settings = $.extend(tinymce.settings, { readonly: 1 });
tinymce.EditorManager.editors.forEach(function (editor) {
tinymce.EditorManager.execCommand('mceRemoveEditor', false, editor.id);
//tinymce.EditorManager.editors = [];
tinymce.EditorManager.execCommand('mceAddEditor', false, editor.id);
});
标签
。this.getBody().setAttribute('contenteditable', false);
请查看完整解决方案,我的服务器端使用的是Asp.net MVC
setup: function (ed) {
ed.on('init', function () {
this.execCommand("fontSize", false, "17px");
$("html,body").scrollTop(0);
@if (ViewBag.desableEdit != null && ViewBag.desableEdit == true)
{
<text>
this.getBody().setAttribute('contenteditable', false);
</text>
}
});
如果您有服务器端条件
,并且它将在返回的HTML中被删除,则可以使用另一种方法来执行此操作。
tinymce.init({
selector: ... ,
....
@if (ViewBag.desableEditExseptExportNumber != null && ViewBag.desableEditExseptExportNumber == true)
{
<text>
readonly: 1,
</text>
}
language: 'ar',
....});
getInit(): any
{
const result = {
base_url: baseUrl,
menubar: false,
branding: false,
height: '500',
selector: 'textarea', // change this value according to your HTML
toolbar: false,
statusbar: false,
readonly: true,
setup: function(ed)
{
ed.settings.readonly = true;
}
};
return result;
}