2015-03-19 96 views
2

我需要一个解决方案,允许我在CKEditor中的各个元素上添加/编辑/删除data-*属性,而无需直接在源编辑器中手动添加它。CKEditor编辑数据属性

我还没有找到任何配置项或插件,允许我这样做。

我该如何去做这件事?

+2

如果没有现有的插件,你必须创建自己的一个。 – AlfonsoML 2015-03-19 12:02:37

回答

2

Here is a working sample based on the example you provided.

您可以添加/编辑/删除数据上的元素属性与this

element.data('extra-info', 'test'); // Appended the attribute data-extra-info="test" to the element. 
alert(element.data('extra-info')); // 'test' 
element.data('extra-info', false); // Remove the data-extra-info attribute from the element. 

http://docs.ckeditor.com/#!/api/CKEDITOR.dom.element-method-data

+0

您的帖子感兴趣的我!什么是“元素”?如何定义它?例如,我有一个“ blabla”,如何获得具有类“st”的跨度的数据时间开始并最终获得“ 55'?谢谢 – Zagloo 2015-03-26 09:04:11

+0

元素是你的跨度。为了帮助我,我需要一个你正在做的事情的样本,以便我知道你是如何创建你的ckeditor控件以及如何插入你的元素的。使用jsfiddle并创建一个示例。 – jnoreiga 2015-03-26 13:50:39

+0

thakns为您提供帮助!我试图做到这一点:http://jsfiddle.net/zagloo/7hvrxw2c/8/ – Zagloo 2015-03-26 14:11:01