简体   繁体   English

如何在图片标签的src属性内传递字符串 <img src=“”> 使用jQuery / JavaScript的?

[英]How to pass string inside src attribute of image tag <img src=“”> using jquery/javascript?

I have a image tag which is : 我有一个图像标签,它是:

<img id="imageUpload" alt="your image" style="display: none;">

I have a base64 code(it is working) of which i have added in string: 我有一个base64代码(正在工作),我在字符串中添加了它:

var imgName="data:image/png;base64,"+base64codes+"";
console.log(imgName);

How to pass the string value inside the src attribute of image using jquery/javascript? 如何使用jquery / javascript在图像的src属性内传递字符串值?

I tried to pass the imgName inside attr using jquery but it is not working. 我试图使用jquery在attr内传递imgName但它不起作用。

$('#imageUpload').attr('src',imgName); 

my console for imgName is : 我的imgName控制台是:

在此处输入图片说明

Your code looks correct. 您的代码看起来正确。 Maybe you just have to remove the style 'display: none' 也许您只需要删除样式“显示:无”

$('#imageUpload').attr('style', '');

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

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