我正在尝试设置div的背景图片 因为我正在尝试
var a = "http://media1.santabanta.com/full2/Indian%20%20Celebrities(F)/Sonam%20Kapoor/sonam-kapoor-40a.jpg";
$("#login-cover").css('background-image', 'url("' + a + '");');
但它没有将图像显示为背景。控制台未显示任何错误
我在 here
之上尝试过答案 0 :(得分:4)
您在css值
的末尾有一个;
var a = "http://media1.santabanta.com/full2/Indian%20%20Celebrities(F)/Sonam%20Kapoor/sonam-kapoor-40a.jpg";
$("#login-cover").css('background-image', 'url("' + a + '")');

#login-cover {
position: absolute;
background-repeat: no-repeat;
width: 100%;
height: 90%;
top: 0px;
left: 0px;
right: 0px;
}
#wrap {
height: 90%;
margin: 0 auto 0;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="wrap">
<div class="container-fluid" id="login-cover"></div>
</div>
&#13;
答案 1 :(得分:3)
答案 2 :(得分:3)
尝试使用此代替您的javascript
var a= "http://media1.santabanta.com/full2/Indian%20%20Celebrities(F)/Sonam%20Kapoor/sonam-kapoor-40a.jpg";
$("#login-cover").css('background', 'url("' + a + '")'); // You had an un-needed semi-colon in your 2nd parameter
答案 3 :(得分:1)
尝试$("#login-cover").css('background-image', 'url("' + a + '")');