嗨,我不知道如何使用 js 将 src 添加到图像//e6 //this code create a new 'img' element let newElementImg = document.createElement("img"); //this code add img from url newElementImg.src = "url('https://cdn.wallpapersafari.com/50/24/PZpRVx.jpg')"; //this code set a list of classes for the 'img' element newElementImg.classList.add("img-fluid"); //append newElementLink to an existing element which has an 'footer-about' ID var imgDiv = document.getElementById('footer-about'); imgDiv.append(newElementImg);它有点工作,但图像不只显示“图像损坏”图标 [像这样] 1
2 回答

慕标5832272
TA贡献1966条经验 获得超4个赞
这是一个 CSS 字符串:
newElementImg.src = "url('https://cdn.wallpapersafari.com/50/24/PZpRVx.jpg')";
您不需要 url() 部分,只需要原始字符串:
newElementImg.src = 'https://cdn.wallpapersafari.com/50/24/PZpRVx.jpg';
添加回答
举报
0/150
提交
取消