gpt4 book ai didi

playframework-2.0 - Play Framework : How to reference image from javascript file

转载 作者:行者123 更新时间:2023-12-02 22:22:40 24 4
gpt4 key购买 nike

我试图在静态 js 脚本中设置图像,但它不起作用。

var _pointer = document.createElement("DIV");
_pointer.style.backgroundImage = 'url(../images/repeater_1x4.jpg)';

它返回这个错误:

GET http://localhost:9000/images/repeater_1x4.jpg 404 (Not Found)

我还尝试了以下操作,因为我将静态资源从公用文件夹映射到 assets/url 路径,它不会返回任何错误,但同样不会显示图像。

var _pointer = document.createElement("DIV");
_pointer.style.backgroundImage = 'url(@routes.Assets.at("images/repeater_1x4.jpg"))';

如果您想知道这是在我的路线文件中:

GET     /assets/*file               controllers.Assets.at(path="/public", file)

正确的做法是什么?我正在使用玩! 2.0,如您所料,我的脚本位于 public/javascripts 中,我的图像位于 public/images 中。

最佳答案

使用:

_pointer.style.backgroundImage = 'url(/assets/images/repeater_1x4.jpg)';

关于playframework-2.0 - Play Framework : How to reference image from javascript file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13460619/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com