Javascript 获取/NaN/in路径

Javascript 获取/NaN/in路径,javascript,php,wordpress,Javascript,Php,Wordpress,我需要向它需要的javascript函数传递一些路径,我正在使用wordpress,所以实际上我正在使用它 在我的wordpress站点的functions.php存档中设置此代码 wp_localize_script('custom', 'WPURLS', array( 'siteurl' => get_option('siteurl') )); 然后像这样在我的javascript存档中调用它 $(function(){ jQuery(document).ready(f

我需要向它需要的javascript函数传递一些路径,我正在使用wordpress,所以实际上我正在使用它

在我的wordpress站点的functions.php存档中设置此代码

wp_localize_script('custom', 'WPURLS', array( 'siteurl' => 
get_option('siteurl') )); 
然后像这样在我的javascript存档中调用它

 $(function(){
    jQuery(document).ready(function() {



    $('#home').backstretch([
        +WPURLS.siteurl+"/images/home-bg-slideshow1.jpg",
        +WPURLS.siteurl+"/images/home-bg-slideshow2.jpg",
        +WPURLS.siteurl+"/images/home-bg-slideshow3.jpg",
        +WPURLS.siteurl+"/images/home-bg-slideshow4.jpg",
        ],  {duration: 5000, fade: 750});
    });
  })
错误:

localhost/wordpress/NaN/images/home-bg-slideshow2.jpg:1未能加载资源:服务器以404状态响应(未找到)

请注意路径

/NaN/images/home-bg-slideshow4.jpg

如果我在localhost上这样做是有原因的,但在网站托管上显然不行

$('#home').backstretch([
        "/wordpress/wp-content/themes/MyTheme/includes/images/home-bg-slideshow1.jpg",
        "/wordpress/wp-content/themes/MyTheme/includes/images/home-bg-slideshow2.jpg",
        "/wordpress/wp-content/themes/MyTheme/includes/images/home-bg-slideshow3.jpg",
        "/wordpress/wp-content/themes/MyTheme/includes/images/home-bg-slideshow4.jpg",
        ],  {duration: 5000, fade: 750});
    });
  })
我能做什么

如果我使用 局部或全局变量->

var templateUrl = '<?= get_bloginfo("template_url"); ?>';
var templateUrl='';
它不起作用,因为它会抛出与使用WPURLS.siteurl相同的错误。如果有人能帮助我,我会很高兴

+WPURLS.siteurl
WPURLS.siteurl
转换为一个数字,但它不起作用,因为字符串的内容不能作为数字进行解析,因此为您提供
NaN

例如,运行以下命令:


console.log(+“hello”)
+WPURLS.siteurl
这将
WPURLS.siteurl
转换为一个数字。只需删除
++
NaN=不是一个数字,因此可能是Fedrico的答案^删除了WPURL之前的+现在的错误是:404(未找到),路径应该类似于以下内容:/wordpress/wp content/themes/MyTheme/includes/images/home-bg-slideshow4.jpg“WPURLS.siteurl+”/images/home-bg-slideshow1.jpg“删除了+,但请注意,如果我删除了另一个+,字符串将不会连接,也不会运行整个应用程序(无论如何都尝试了)。如果没有您的帮助,它将不会解决问题,谢谢