如何使CKEditor只读?

时间:2015-08-01 20:23:31

标签: ckeditor readonly

我使用此代码使ckeditor只读:

( function()
{
   var cancelEvent = function( evt )
      {
         evt.cancel();
      };

   CKEDITOR.editor.prototype.readOnly = function( isReadOnly )
   {
      // Turn off contentEditable.
        this.element.$.disabled = isReadOnly;
        this.element.$.contentEditable = !isReadOnly;
        this.element.$.designMode = isReadOnly ? "off" : "on";

      // Prevent key handling.
      this[ isReadOnly ? 'on' : 'removeListener' ]( 'key', cancelEvent, null, null, 0 );
      this[ isReadOnly ? 'on' : 'removeListener' ]( 'selectionChange', cancelEvent, null, null, 0 );

      // Disable all commands in wysiwyg mode.
      var command,
         commands = this._.commands,
         mode = this.mode;

      for ( var name in commands )
      {
         command = commands[ name ];
         isReadOnly ? command.disable() : command[ command.modes[ mode ] ? 'enable' : 'disable' ]();
         this[ isReadOnly ? 'on' : 'removeListener' ]( 'state', cancelEvent, null, null, 0 );
      }
   }
} )();

在此之后我使用此代码:

  $(document).ready(function () {
         $("#status_news1").click(function () {
             if (document.getElementById("status_news1").selectedIndex == 0 || document.getElementById("status_news1").selectedIndex == 2) {
                 CKEDITOR.instances.content1.readOnly( true ); 
             }
             else {
                 CKEDITOR.instances.content1.readOnly( false );
             }
         });

     });

问题是我有这个错误: CKEDITOR.instances.content1.readOnly不是函数。 我该如何解决这个错误?如何使用select元素“status_news1”来改变readonly的状态?

1 个答案:

答案 0 :(得分:0)

API已经提供了一种方法:setReadOnly