尝试实现这个 jquery 插件 http://www.myjqueryplugins.com/jquery-plugin/jrating我无法在 js 文件中设置星星的路径。它不可能在 js 文件中使用 php,对吗? 因为我需要将这些星星路径设置在 webroot 文件夹中,如果没有 WWW_ROOT 常量,我不知道该怎么做
(function($) {
$.fn.jRating = function(op) {
var defaults = {
bigStarsPath : 'icons/stars.png'
...
最佳答案
只需将其设为 absolute URL而不是相对 URL:
(function($) {
$.fn.jRating = function(op) {
var defaults = {
bigStarsPath : '/icons/stars.png' //<-- notice the "/" before "icons"
...
这告诉它在“webroot”文件夹中寻找“icons”文件夹。
对于 webroot 中的任何其他文件也是如此。有时你想包含库或其他东西中的 css 或 javascript 文件 - 在这种情况下,你可以通过先设置“/”来包含它 - 如下所示:/bootstrap/js/main.js
.
关于javascript - cakephp - js文件中图像的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20729497/