【问题标题】:CKEditor 4 Manually Invoking Numbered ListCKEditor 4 手动调用编号列表
【发布时间】:2013-10-29 04:27:04
【问题描述】:

鉴于我已禁用工具栏并使用自己的标记创建了自己的工具栏(具有类似词缀的功能)。

当我单击工具栏的相应按钮时,我需要重新创建 ckeditor 工具栏的编号列表和项目符号列表按钮的功能。

没有

editor.execCommand('numberedlist')
editor.execCommand('numberedListStyle')
editor.execCommand('bulletedlist')
editor.execCommand('bulletedListStyle')

有效。

也许我弄乱了参数,我需要传递更多参数。

我需要在 ckeditor 上调用什么命令来根据当前选择创建有序和无序列表?

UPD

当我在 ckeditor 中选择一些文本时,打开我的网络检查器并在控制台中输入:

> content_editors.ru.execCommand('bold')
  true

它就像一个魅力,文字变得粗体,但 numberedlistbulletedlist 没有运气:

> content_editors.ru.execCommand('numberedlist')
  false
> content_editors.ru.execCommand('bulletedlist')
  false

在我禁用 config.js 中的工具栏插件之前,列表一直有效:

config.removePlugins = 'toolbar'
config.allowedContent = 'p h3 h4 h5 h6 strong em u; a[!href]; img[!src]'

UPD2

所以为了禁用工具栏而深入研究我所做的事情。我不允许ul and ol标签!

这么简单

// config.allowedContent = 'p h3 h4 h5 h6 strong em u; a[!href]; img[!src]'
config.allowedContent = 'p h3 h4 h5 h6 strong em u; a[!href]; img[!src]; ul ol;'

成功了!

【问题讨论】:

    标签: javascript ckeditor


    【解决方案1】:

    您需要致电:

    editor.execCommand( 'numberedlist' );
    editor.execCommand( 'bulletedlist' );
    

    ofc editor 必须是有效的 ckeditor 实例对象。您可以从CKEDITOR.instances 获取实例。

    即对于http://ckeditor.com/demo,您必须执行以下调用:

    CKEDITOR.instances.editor1.execCommand( 'numberedlist' );
    

    【讨论】:

    • 它只返回 false 并且所选文本没有任何反应。我有有效的ckeditor 实例,因为我可以成功执行bold, link, etc 之类的命令。但不是numberedlist and bulletedlist
    • Marek,感谢您推动我进一步调查,为什么应该工作的代码只返回 false。你的回答是对的。如果允许ul and ol,这是可行的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-22
    • 2013-04-01
    • 1970-01-01
    • 2018-04-02
    相关资源
    最近更新 更多