【发布时间】:2012-11-19 19:20:48
【问题描述】:
我正在尝试在静态 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 中,正如你所料。
【问题讨论】: