Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery wordpress模板路径_Jquery_Wordpress_Variables_Path_Autostart - Fatal编程技术网

jquery wordpress模板路径

jquery wordpress模板路径,jquery,wordpress,variables,path,autostart,Jquery,Wordpress,Variables,Path,Autostart,需要一些jQuery方面的帮助。我是一个有点noobjquery智慧的人 我在一个变量中得到了我的模板\u dir: $('#someID').click(function() { var templateDir = '<?php bloginfo("template_directory") ?>'; if(autoStart) { $(this).html('<img src=" 'TEMPLATEDIR HERE' /images/pauze

需要一些jQuery方面的帮助。我是一个有点noobjquery智慧的人

我在一个变量中得到了我的模板\u dir:

$('#someID').click(function() {
    var templateDir = '<?php bloginfo("template_directory") ?>';
    if(autoStart) {
        $(this).html('<img src=" 'TEMPLATEDIR HERE' /images/pauze-play.png" />');
    } else {
        $(this).html('<img src=" 'TEMPLATEDIR HERE' /images/pauze-play.png" />');
    }
    autoStart = !autoStart;
    $('#mainSlider.royalSlider').royalSlider('toggleAutoPlay');
 });
$('#someID')。单击(函数(){
var templateDir='';
如果(自动启动){
$(this.html(“”);
}否则{
$(this.html(“”);
}
autoStart=!autoStart;
$('#mainslaider.royalslaider').royalslaider('toggleAutoPlay');
});
我做了一些stackoverflow搜索,并试图找出它,但由于缺乏技能,我所做的并没有起作用,尽管我觉得它相当简单

我以为是这样的:

<img src=" 'templateDir +' /images/pauze-play.png" />'
'
但是没有

提前谢谢


/Paul

也许您可以将变量放入一个隐藏的范围,放在php的某个地方,如下所示:
yourtheme
,然后您可以用javascript捕捉它:

var mytheme=$(“.mythemepath”).text()

您使它变得复杂。我不明白为什么在不调用javascript中的图像时将模板目录分配给var

以下方法可以很好地工作:

<img src="<?php bloginfo("template_directory") ?>/images/pauze-play.png" />
/images/pauze play.png/>
编辑


$('#someID')。单击(函数(){
如果(自动启动){
$(this.html('/images/pauze play.png/>);
}否则{
$(this.html('/images/pauze play.png/>);
}
autoStart=!autoStart;
$('#mainslaider.royalslaider').royalslaider('toggleAutoPlay');
});

代码danyo poste可以正常工作,但在您选择的将templateDir定义为javascript变量的路线上,您将有:

$(this).html('<img src="' + templateDir + '/images/pauze-play.png" />');
$(this.html(“”);
注意:“”和“/”之间没有空格。这可能是你出错的地方

另外,您可能希望将templateDir声明为全局变量。所以你会:

var templateDir = '<?php bloginfo("template_directory"); ?>';
jQuery('.selector').click(function(){ ...
var templateDir='';
jQuery('.selector')。单击(函数(){。。。

您试图在客户端javascript中包含服务器端技术。这是行不通的。这是一种不好的做法吗?需要交换pauze的图像才能播放。您提供的代码已在模板文件中使用。
var templateDir = '<?php bloginfo("template_directory"); ?>';
jQuery('.selector').click(function(){ ...