我想将 img-responsive 添加到从 Summernote 文本获取的一些 HTML 中的所有 img 中。我以为这会起作用,但事实并非如此。也许是因为 img 标签没有 class 属性?
html 示例
<p><img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABI...."></p>
这是我的代码:
var rawHtml = $("#summernote").summernote('code');
$(rawHtml).find('img').each(function () {
$('img').addClass('img-responsive');
});
最佳答案
// v 0.8.9
$('#summernote').summernote({
callbacks: {
onChange: function(contents, $editable) {
//find images on note-editable class,
var imgs = $('.note-editable').find("img");
$.each(imgs, function(index, img){
//bootstrap 3
$(img).addClass("img-responsive");
//bootstrap 4
//$(img).addClass("img-fluid");
})
}
}
});
关于jQuery addClass到summernote数据中的所有img,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46439305/