【问题标题】:How to make CKEditor readonly?如何使CKEditor只读?
【发布时间】:2015-08-02 06:30:31
【问题描述】:

我使用此代码使 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 is not a function。 我该如何解决这个错误?如何使用选择元素“status_news1”更改只读状态?

【问题讨论】:

    标签: ckeditor readonly


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-18
      • 2011-10-18
      • 2018-08-07
      • 2019-09-01
      • 2017-12-19
      相关资源
      最近更新 更多