简体   繁体   中英

jquery change background-image not working

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

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

在此处输入图片说明

在此处输入图片说明

It should say my website name in the url path there so I add it to the jquery:

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

and get:

jquery.js:6685 GET http://localhost:8888/the_vegan_repository/the_vegan_repository/assets/images/home_page/auckland.jpg 404 (Not Found)

How do I make it find my resource by pointing it to the_vegan_repository/assets/images/home_page/auckland.jpg ?

Try this:

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

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

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