是否可以修改此操作以删除所有< img>标签,然后再添加新标签 [英] Is it possibe to modify this to remove all <img> tags before adding the new one
本文介绍了是否可以修改此操作以删除所有< img>标签,然后再添加新标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经包括我的部分JavaScript,我想知道的是成功后,它添加一个图像到编辑器。但是,如何在添加新的图像之前先从编辑器中删除所有图像?
I have included part of my javascript below and what i want to know is upon success it adds an image to the editor. But how do i make it first remove all images from the editor before adding the new one ?
onComplete: function (file, json) {
$('#upload-image').attr('disabled', false);
$('.error-upload').remove();
if (json['success']) {
alert(json['success']);
var oEditor = CKEDITOR.instances.forum_signature;
var value = document.getElementById('forum_signature').value;
if (oEditor.mode == 'wysiwyg') {
oEditor.insertHtml('<img src="' + json['image'] + '" alt="Image" /><p> </p>');
} else {
alert('You must be in WYSIWYG mode!');
}
}
if (json['error']) {
$('#upload').after('<span class="error-upload" style="color:red;">' + json['error'] + '</span>');
}
if (json['error_size']) {
$('#upload').after('<span class="error-upload" style="color:red;">' + json['error_size'] + '</span>');
}
$('.loading').remove();
}
Thanx有任何帮助。
Thanx for any help.
Justine
推荐答案
oEditor
c $ c> CKEDITOR.editor 类。因此,这是正确的解决方案:
oEditor
is an instance of CKEDITOR.editor
class. Therefore this is the right solution:
if ( oEditor.mode == 'wysiwyg' && oEditor.editable() ) {
var images = oEditor.editable().getElementsByTag( 'img' );
while ( images.count() ) {
var image = images.getItem( 0 ); // This is a live collection.
// Whether this is a real image, not e.g. anchor icon.
if ( image.data( 'cke-saved-src' ) )
image.remove();
}
}
这篇关于是否可以修改此操作以删除所有< img>标签,然后再添加新标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文