jquery更改背景图像不起作用

时间:2016-03-16 04:44:42

标签: javascript jquery

function slideSwitch() {
    $("#bgvid").css("background-image", "url(/assets/images/home_page/auckland.jpg)");
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});

enter image description here

enter image description here

应该在url路径中说出我的网站名称,所以我将它添加到jquery:

function slideSwitch() {
    $("#bgvid").css("background-image", "url(the_vegan_repository/assets/images/home_page/auckland.jpg)");
}

并获得:

  

jquery.js:6685 GET   http://localhost:8888/the_vegan_repository/the_vegan_repository/assets/images/home_page/auckland.jpg   404(未找到)

如何通过将资源指向the_vegan_repository/assets/images/home_page/auckland.jpg来查找资源?

1 个答案:

答案 0 :(得分:1)

试试这个:

function slideSwitch() {
    $("#bgvid").css("background-image", "url('/the_vegan_repository/assets/images/home_page/auckland.jpg')");
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});