繁体   English   中英

使用js将background-image设置为html

[英]set background-image to html using js

bg = "http//example.com/img.png";
html = '<div style="background-image:url('+bg+')>'

我上面的串联有什么问题? 我确实看到了img路径,但没有显示背景图像。

关闭报价

html = '<div style="background-image:url('+bg+')">'

您的代码应该像

bg = "http//example.com/img.png";
html = '<div style="background-image:url('+bg+')">'

最后缺少引号

行动。 抱歉。!! 只需关闭您的qoutes。

'<div style="background-image:url('+bg+')">'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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