简体   繁体   中英

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:

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?

I tried to pass the imgName inside attr using jquery but it is not working.

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

my console for imgName is :

在此处输入图片说明

Your code looks correct. Maybe you just have to remove the style 'display: none'

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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