开发者

Change background image of a div from <input> without page refresh

开发者 https://www.devze.com 2023-03-11 17:29 出处:网络
I have <input type=\"file\"> tag. I need to select an image and change the background of the开发者_如何学运维 image to the input image without refreshing or reloading the page. Is it possible ?

I have <input type="file"> tag. I need to select an image and change the background of the开发者_如何学运维 image to the input image without refreshing or reloading the page. Is it possible ? If yes, how to do it ?


It is possible, but you'd have to make an AJAX file uploader - Javascript can't access the contents of a file input any any meaningful way.


You can use jQuery and do this:

$('#imgID').attr ('src', 'new path');

That will change the image without reloading the page.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号