javascript - CKeditor 使内联编辑器只读

标签 javascript ckeditor

我正在使用 ckeditor 的内联编辑器来创建 html 内容。我怎样才能让它只读并只显示预览模式的内容。我尝试了以下配置,但它对我不起作用。

this.editorInstance.setReadOnly( true); 

这里 this.editorIntance 是我的编辑器。我只想在预览模式下显示内容,不想显示编辑器的工具栏。

最佳答案

使用以下脚本使 CKeditor 只读。在 toggleReadOnly 函数中传递“true”或“false”参数,以相应地禁用或启用 ckeditor。

var editor;

// The instanceReady event is fired when an instance of CKEditor has finished
// its initialization.
CKEDITOR.on( 'instanceReady', function ( ev ) {
    editor = ev.editor;

    // Show this "on" button.
    document.getElementById( 'readOnlyOn' ).style.display = '';

    // Event fired when the readOnly property changes.
    editor.on( 'readOnly', function () {
        document.getElementById( 'readOnlyOn' ).style.display = this.readOnly ? 'none' : '';
        document.getElementById( 'readOnlyOff' ).style.display = this.readOnly ? '' : 'none';
    } );
} );

function toggleReadOnly( isReadOnly ) {
    // Change the read-only state of the editor.
    // http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-setReadOnly
    editor.setReadOnly( isReadOnly );
}

请引用工作演示:https://jsfiddle.net/rbua57pq/3/

关于javascript - CKeditor 使内联编辑器只读,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39891248/

相关文章:

javascript - Chrome 如何获取 gist json 文件?这不是禁止的吗?

javascript - 如何使用 jQuery 或 javascript 将 div 放在页面的最顶部?

javascript - CKEditor baseHref 不工作,编辑器在缩小/捆绑后不工作

jquery - 使用 Jquery 限制/计数 CKEditor 中的字符

audio - CKeditor的非Flash音频插件

javascript - 在 JavaScript 中如何在循环中添加延迟

javascript - 将数组字符串转换为数组javascript

javascript - JavaScript 中一长串整数的转换问题

javascript - iframe 中元素的 CKEditor 内联编辑器

javascript - CKEditor & JavaScript - 在 CKEditor 中调整高度和宽度