我已经编写了自己的插件,可以生成一个简单的链接。 奇怪的是我无法编辑“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'));
}
}
创建和编辑属性非常有效。
你不知道是什么问题?
谢谢。
答案 0 :(得分:3)
由于各种内部原因,CKEditor在运行时使用data-cke-saved-href
属性复制href
。那么输出中的内容是什么样的
<p>I'm a <a href="http://foo.com">plain link</a>.</p>
<p>I'm a <a href="mailto:foo@bar.com?subject=Subject&body=Body">mailto link</a>.</p>
实际上是编辑器DOM中的不同之处
<p>I'm a <a data-cke-saved-href="http://foo.com" href="http://foo.com">plain link</a>.</p>
<p>I'm a <a data-cke-saved-href="mailto:foo@bar.com?subject=Subject&body=Body" href="mailto:foo@bar.com?subject=Subject&body=Body">mailto link</a>.</p>
每次更改data-
时都会更新href
属性,事情应该正确。