gpt4 book ai didi

Jquery 中的 PHP 路径

转载 作者:行者123 更新时间:2023-11-30 06:45:38 25 4
gpt4 key购买 nike

我正在尝试使用以下代码在 WordPress 中集成一个 mp3 播放器:

 $(document).ready(function(){
var description = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit';
var path_php = "<?php bloginfo('template_directory'); ?>";

$('body').ttwMusicPlayer(myPlaylist, {
autoPlay:false,
description:description,
jPlayer:{
swfPath: path_php+'/plugin/jquery-jplayer'
}
});
});

播放器以一种奇怪的方式只在 Opera 和 IE8 中工作。该脚本是正确集成的,因为如果我为 var php_path 编写博客的绝对路径,它就可以工作。

可以帮助我解决我所缺少的吗?谢谢!

稍后编辑:如果您对如何在上面的 jquery 代码中加载 wp 模板路径有不同的想法,我愿意接受。

这是上面代码的浏览器输出:

  $(document).ready(function(){
var description = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit';
var path_php = "http://localhost/mywebsite/wp-content/themes/mythemename";

$('body').ttwMusicPlayer(myPlaylist, {
autoPlay:false,
description:description,
jPlayer:{
swfPath: path_php+'/plugin/jquery-jplayer'
}
});
});

最佳答案

在WordPress中

plugins_url()

返回包含域的插件 url。

$(document).ready(function(){
var description = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit';
var path_php = "<?php print plugins_url(); ?>";

$('body').ttwMusicPlayer(myPlaylist, {
autoPlay:false,
description:description,
jPlayer:{
swfPath: path_php.match(/http:\/\/[^\/]+(.*)/)[1]+'jquery-jplayer'
}
});
});

所以应该用任何东西替换 http://和域,最后只剩下插件路径和 jquery-jplayer。

关于Jquery 中的 PHP 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7202252/

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