2012-10-23 35 views
6

如何使用外部JS启用/禁用CKEditor的保存按钮?我不想完全删除它,只需更改灰色和彩色图标之间的外观,以便更方便用户使用。以编程方式控制保存按钮启用/禁用状态

我保存按钮,像这样产生的:

CKEDITOR.plugins.registered['save'] = 
{ 
    init : function(editor) 
    { 
     var command = editor.addCommand('save', { 
      modes : { wysiwyg:1, source:1 }, 
      exec : function(editor) { 
       if(My.Own.CheckDirty()) 
        My.Own.Save(); 
       else 
        alert("No changes."); 
      } 
     }); 
     editor.ui.addButton('Save',{label : '',command : 'save'}); 
    } 
} 

回答

16

在这里你去:

对于3.6.x的:

CKEDITOR.instances.yourEditorInstance.getCommand('save').disable(); 
CKEDITOR.instances.yourEditorInstance.getCommand('save').enable(); 

对于4.x版:

CKEDITOR.instances.yourEditorInstance.commands.save.disable(); 
CKEDITOR.instances.yourEditorInstance.commands.save.enable(); 
+0

优秀!谢谢你让我走向正确的轨道。我必须改变它一点,因为我的实例没有“命令”变量,我用'CKEDITOR.instances.yourEditorInstance.getCommand('save')。disable()' – Nenotlep

+1

谢谢,我在CKEditor 4上检查过它。其中'getCommand()'不再是必需的。更新了我的答案。 – oleq