简体   繁体   English

如何在弹出窗口中显示 base64 图像

[英]How to display a base64 image in a popover

I've successfully displayed a base64 image on my webpage (a MS dynamics portal built on liquid templates) with this code, and then appending the element to a div:我已经使用此代码在我的网页(基于液体模板构建的 MS 动态门户)上成功显示了 base64 图像,然后将该元素附加到 div:

imageElementCaseNote.src = 'data:image/png;base64, ${Picture}';

The issue I have is: how to the set the 'data-content' attribute of imageElementCaseNote , I tried the following, but get [object HTMLImageElement] instead of the image.我遇到的问题是:如何设置imageElementCaseNote的 'data-content' 属性,我尝试了以下操作,但得到[object HTMLImageElement]而不是图像。

imageElementCaseNote.setAttribute('data-content', 'data:image/png;base64, ${Picture}');

What do I need to do to do?我需要做什么? I think the data needs to be added as html but I can't work out how to do it.我认为数据需要添加为 html,但我不知道该怎么做。

All help appreciated.所有帮助表示赞赏。

There were two things I was missing, one obvious the other less so.我错过了两件事,一件很明显,另一件则不太明显。

obvious: I needed to wrap the data in an image tag:显而易见:我需要将数据包装在图像标签中:

popImage = '<img src="' + imageElementCaseNote.src + '"/>';
ImageElementCaseNote.setAttribute('data-content', popImage);

less obvious: I needed to set the data-html attribute:不太明显:我需要设置 data-html 属性:

imageElementCaseNote.setAttribute('data-html', 'true');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM