CKEditor 4 手动调用编号列表

CKEditor 4 Manually Invoking Numbered List

本文关键字:编号 列表 调用 CKEditor      更新时间:2023-09-26

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

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

都不是

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

工程。

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

我需要在 ckeditor 上调用什么命令才能从当前选择中创建有序和无序列表?

UPD

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

> 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;'

成功了!

您需要调用:

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

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

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

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