2
我試圖在靜態js腳本中設置圖像,但它不起作用。播放框架:如何從JavaScript文件引用圖像
var _pointer = document.createElement("DIV");
_pointer.style.backgroundImage = 'url(../images/repeater_1x4.jpg)';
它返回此錯誤:
GET http://localhost:9000/images/repeater_1x4.jpg 404 (Not Found)
我也試過以下,因爲我已經從公用文件夾的資產/ 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)
什麼是做到這一點的正確方法是什麼?我正在使用Play! 2.0,我的腳本是公開的/ javascripts和我的圖像公開/圖像,你可能會期望。
謝謝!做了這項工作 – Nocturn