使ckeditor只在页面加载时读取

时间:2013-08-29 13:48:46

标签: html ckeditor readonly

我想在页面上将ckeditor设为只读,并且只能是只读的。我该怎么做呢?我试图改进下面的代码来做到这一点,但我似乎无法弄明白。

我让编辑器有一个切换只读模式,它加载为非只读模式。 (这不是我想要的,但这是我得到的最接近的)这是我的代码:

window.onload = function () {
    CKEDITOR.replace('textBox', );
}

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.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#setReadOnly
    editor.setReadOnly(isReadOnly);
}

html

 <p>
    <textarea class="ckeditor" id="editor1" name="editor1" style="height:400px;width:900px">${alert.html}</textarea>
</p>
<p>
    <input id="readOnlyOn" onclick="toggleReadOnly();" type="button" value="Make it read-only"
    style="display:none" />
    <input id="readOnlyOff" onclick="toggleReadOnly( false );" type="button"
    value="Make it editable again" style="display:none" />
</p>

1 个答案:

答案 0 :(得分:6)

disabled定义<textarea>属性,编辑器将以只读方式启动:

<textarea id="editor" disabled>Cow says moo!</textarea>

请参阅the sample fiddle