简体   繁体   中英

Pass variable in image url

var a = "C:/xyz/ABC/mno/abc.jpg";

I want to pass this veriable inside:

$('.abc').css( "background-image", "url(a)");

Its not working how to do this?

你很接近,你只需要打破background-image的双引号并使用字符串连接来应用a变量:

$('.abc').css( "background-image", "url(" + a + ")");
var b = "url(" +'\"'+  a +'\"'+ ")";
$('.abc').css("background-image", b);

Are you kidding? $('.abc').css("background-image",'url('+a+')')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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