javascript - jquery 更改背景图像不起作用

标签 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 (Not Found)

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

最佳答案

试试这个:

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

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

关于javascript - jquery 更改背景图像不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36026968/

相关文章:

javascript - 如何在 Bootstrap 下拉菜单中使用事件类

javascript - d3js - 平滑永动的 SVG 圆

javascript - jQuery 计算输入的内容

jQuery-UI 在后台单击时关闭模式对话框

javascript - ASP.NET MVC 5 - jQuery AJAX 有效,Fetch API 无效

javascript - 初学者 HTML 和 Javascript : Changing input slider values to paragraphField. innerHTML

javascript - 在谷歌饼图中加载数据

javascript - 关闭时恢复幻灯片切换按钮文本

javascript - 只接受季度 float

jquery - 使用 javascript 和 css3 转换以动态高度移动 div