2015-03-19 97 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