因为我使用CKEditor (http://ckeditor.com/),所以我遇到了一个问题。问题是我找不到一种方法来使编辑器成为ReadOnly,而且我不能只使用文本区,因为我想保持一致性。我已经在StackOwerflow上看到过很多这样的问题,但没有一个有效或者太老了。
到目前为止,我的代码只是显示/初始化编辑器:
$(document).ready(function(){
CKEDITOR.replace( 'ckeditor', {
on: {
// Check for availability of corresponding plugins.
pluginsLoaded: function( evt ) {
var doc = CKEDITOR.document, ed = evt.editor;
if ( !ed.getCommand( 'bold' ) )
doc.getById( 'exec-bold' ).hide();
if ( !ed.getCommand( 'link' ) )
doc.getById( 'exec-link' ).hide();
}
}
});
});我使用最新的CKEditor版本(v.4.1.1全包)
提前感谢!:)
发布于 2013-04-26 21:04:10
在docs readOnly中,您可以将配置设置为readOnly
config.readOnly = true;还有一个example,它显示通过一个方法设置它
editor.setReadOnly( true);发布于 2014-07-10 00:01:30
尝试使用以下代码行,
<textarea id="editor1" name="editor1" ></textarea>
<textarea id="editor2" name="editor2" ></textarea>
<input type="button" onclick="EnableEditor2()" value="EnableEditor2" />
<script>
$(document).ready(function () {
//set editor1 readonly
CKEDITOR.replace('editor1', {readOnly:true});
CKEDITOR.replace('editor2');
//set editor2 readonly
CKEDITOR.instances.editor2.config.readOnly = true;
});
function EnableEditor2() {
CKEDITOR.instances.editor2.setReadOnly(false);
}
</script>发布于 2013-04-26 21:05:08
你试过this吗?
他们说,这应该是可行的
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
<form action="sample_posteddata.php" method="post">
<p>
<textarea class="ckeditor" id="editor1" name="editor1" cols="100" rows="10"><p>This is some <strong>sample text</strong>. You are using <a href="http://ckeditor.com/">CKEditor</a>.</p></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>
</form>https://stackoverflow.com/questions/16237093
复制相似问题