尝试禁用ckeditor中的按钮时出错



我正在尝试在页面加载时动态禁用一个按钮,尽管进行了一些检查,但编辑器是实例未定义的。我加载在页面的页面:

ckeditor.js
CKEDITOR.replace( 'message', {
customConfig: 'ckeditor_config'
});
check.js

在check.js文件中,我正在尝试动态禁用按钮:

jQuery(document).ready(function ($) {
var pollcatid = jQuery('#poll_catid').val();
if(pollcatid !== undefined)
{
CKEDITOR.instances.message.getCommand( 'polls' ).enable();
}
else
{
CKEDITOR.instances.message.getCommand( 'polls' ).disable();
}
});

在页面加载上,我有以下错误:

Uncaught TypeError: CKEDITOR.instances.message.getCommand(...) is undefined

那么,为什么在check.js文件中出现错误呢?

我已经想好了如何做到这一点,通过这样做:

CKEDITOR.on('instanceReady', function(evt){
// Do your bindings and other actions here for example
// You can access each editor that this event has fired on from the event
var editor = evt.editor;
var pollcatid = jQuery('#poll_catid').val();
if(pollcatid !== undefined)
{
editor.getCommand( 'polls' ).enable();
}
else
{
editor.getCommand( 'polls' ).disable();
}
});

最新更新