将javascript元素背景图片设置为等于下载网址

 收藏

I am trying to give a javascript element a background image. This url is stored in a database and is not a string but a file path: https://firebasestorage.googleapis.com/v0/b/fir-firebase-182ca.appspot.com/o/images%2FScreenshot%20(2).png?alt=media&token=0edf4c43-e791-48b1-b2f4-b8ec5e65e296

我还在制作一个javascript元素(即div),以将其背景图像设置为此链接:

var icon = document.createElement('img');
icon.style.cssText = "background-color: red;"
//icon.src = "'" + url + "'";
var parent = document.getElementById("loggedDisplay");
parent.appendChild(icon);

到目前为止,我还无法使它正常工作。我将如何制作此背景图片=网址

回复