javascript - CKeditor 自己的带对话框的插件

标签 javascript ckeditor

我已经编写了自己的插件来生成一个简单的链接。 奇怪的是我不能编辑“href”属性。可以编辑其他属性。

这个元素不起作用:

{
    type: 'text',
    id: 'url',
    label: 'URL',
    commit: function(element) {
        element.setAttribute('href', this.getValue());
    },
    setup: function(element) {
        this.setValue(element.getAttribute('href'));
    }
}

当我创建链接时,会写入 href 属性。当我编辑链接时,“href”属性没有改变。奇怪!

当我更改上面的代码并将属性名称重写为“href-s”时:

{
    type: 'text',
    id: 'url',
    label: 'URL',
    commit: function(element) {
        element.setAttribute('href-s', this.getValue());
    },
    setup: function(element) {
        this.setValue(element.getAttribute('href-s'));
    }
}

创建和编辑属性完美运行。

不知道是什么问题?

谢谢。

最佳答案

由于各种内部原因,CKEditor 在运行时使用data-cke-saved-href 属性复制href。那么输出结果会是什么样子

<p>I&#39;m a <a href="http://foo.com">plain&nbsp;link</a>.</p>

<p>I&#39;m a <a href="mailto:foo@bar.com?subject=Subject&amp;body=Body">mailto link</a>.</p>

实际上在编辑器 DOM 中有些不同

<p>I'm a <a data-cke-saved-href="http://foo.com" href="http://foo.com">plain&nbsp;link</a>.</p>

<p>I'm a <a data-cke-saved-href="mailto:foo@bar.com?subject=Subject&amp;body=Body" href="mailto:foo@bar.com?subject=Subject&amp;body=Body">mailto link</a>.</p>

每次更改 href 时更新 data- 属性,一切都会正常进行。

关于javascript - CKeditor 自己的带对话框的插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28427516/

相关文章:

php - 从 div 获取表单输入 laravel 的内容

javascript - CKEDITOR 无法使用 De CoupledEditor 查看内容区域

javascript - XPages:配置文件切换

javascript - 使用 CKeditor 上传文件

javascript - Google Analytics 跟踪文件下载

javascript - AngularJs - 模块已定义但仍然出现 "not available"错误

javascript - 如何自定义ckeditor工具栏按钮行为?

CKEditor 5 如何从任何小部件/模型/ View 获取点击、更新和删除事件

javascript - 从另一个域获取 html 内容时出错

javascript - 错误 : Unknown action from worker: ReaderHeadersReady when loading a PDF using PDF. js