[英]How to add an ID to an image in CKEditor?
Everytime a user inserts an image into the page (I'm using CKEditor 4 inline editing) I want to add an ID sequentially eg id=Image1
, id=Image2
, id=Image3
so that my server can loop through them and know how many images there are on the page and how to process them. 每次用户将图像插入页面时(我正在使用CKEditor 4内联编辑)我想按顺序添加ID,例如
id=Image1
, id=Image2
, id=Image3
这样我的服务器就可以遍历它们并知道有多少页面上有图像以及如何处理它们。
I noticed there is an addClass()
function in CKEditor, but how do I add an ID? 我注意到CKEditor中有一个
addClass()
函数,但是如何添加ID呢? I just need some way to uniquely and programmatically tell each inserted image apart from the other. 我只需要一些方法来唯一地和编程地告诉每个插入的图像与另一个。
I can't understand how to do this at all. 我根本无法理解如何做到这一点。 Even a pointer in the right direction would be very appreciated.
即使是正确方向的指针也会非常感激。
If you have created the element using something like: 如果您使用以下内容创建了元素:
var myImg = document.createElement('img');
then you can add an id to by simply setting the id property of that new DOM element:- 然后你可以通过简单地设置新DOM元素的id属性来添加一个id: -
myImg.id = "Image1";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.