尝试禁用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();
        }
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章