Is there a way to set background-image as a base64 encoded image?

后端 未结 9 2257
执念已碎
执念已碎 2020-12-02 16:09

I want to change background dynamically in JS and my set of images is in base64 encoded. I try:

document.getElementById(\"bg_image\").style.backgroundImage =         


        
9条回答
  •  情歌与酒
    2020-12-02 16:57

    What I usually do, is to store the full string into a variable first, like so:

    
    

    Then, where I want either JS to do something with that variable:

    
    

    You could reference the same variable via PHP directly using something like:

    
    

    Works for me ;)

提交回复
热议问题