如何在CKEditor中将类添加到父级

时间:2015-01-24 03:22:28

标签: ckeditor wrapper parent addclass

我使用simpleuploads插件。 上传图片时,我需要在课堂上添加一个课程。

这是在图片上传过程后粘贴的HTML代码

<div><img src="link/to/image"><img src="link/to/image2"></div>

现在我需要将类添加到'div'元素,但我不知道如何。 要删除&lt; height width 属性img&gt;我使用此代码的元素:

<script>
CKEDITOR.on('instanceReady', function(e) {
    e.editor.on( 'simpleuploads.finishedUpload' , function(ev)
    {
            var element = ev.data.element;
            if (element.getName() == 'img')
            {
                var img = element.$;
                img.removeAttribute('width');
                img.removeAttribute('height');
                ev.stop(); // Stop the event in case the listener is inserted twice
            }
    });
});
</script>

如果有人可以帮我添加课程,那就太棒了。

1 个答案:

答案 0 :(得分:1)

这是正确的代码:

<script>
CKEDITOR.on('instanceReady', function(e) {
e.editor.on( 'simpleuploads.finishedUpload' , function(ev)
{
        var element = ev.data.element;
        if (element.getName() == 'img')
        {
            var img = element.$;
            img.removeAttribute('width');
            img.removeAttribute('height');
            img.parentNode.setAttribute('class','classname');
            ev.stop(); // Stop the event in case the listener is inserted twice
        }
    });
});
</script>