【问题标题】:jquery wordpress template pathjquery wordpress 模板路径
【发布时间】:2013-07-31 08:55:20
【问题描述】:

需要一点 jQuery 的帮助。我有点 jQuery 的菜鸟。

我在 var 中获得了我的 template_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');
 });

我做了一些 stackoverflow 搜索并试图弄清楚,但由于缺乏技能,我所做的它不起作用,尽管我觉得它相当简单。

以为是这样的:

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

但是没有……

提前致谢

/保罗

【问题讨论】:

标签: jquery wordpress variables path autostart


【解决方案1】:

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

$(this).html('<img src="' + templateDir + '/images/pauze-play.png" />');

注意: "' 和 '/ 之间没有空格。这可能是您出错的地方。

您可能还想将 templateDir 声明为全局变量。所以你会有:

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

【讨论】:

    【解决方案2】:

    也许你可以把变量放到一个隐藏的 span 中,用 php 放在某个地方,像这样:
    &lt;span class='hidden mythemepath'&gt;yourtheme&lt;/span&gt;,然后你可以用 javascript 捕捉它:
    var mytheme = $(".mythemepath").text();

    【讨论】:

      【解决方案3】:

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

      以下将正常工作:

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

      编辑

      <script>
      $('#someID').click(function() {
          if(autoStart) {
              $(this).html('<img src="<?php bloginfo("template_directory") ?>/images/pauze-play.png" />');
          } else {
              $(this).html('<img src="<?php bloginfo("template_directory") ?>/images/pauze-play.png" />');
          }
          autoStart = !autoStart;
          $('#mainSlider.royalSlider').royalSlider('toggleAutoPlay');
       });
      </script>
      

      【讨论】:

      • 它需要从 pauze 交换图像才能播放。你提供的代码我都准备好在模板文件中使用了。
      猜你喜欢
      • 2011-02-20
      • 2018-08-25
      • 2013-06-17
      • 2017-12-07
      • 1970-01-01
      • 1970-01-01
      • 2018-03-31
      • 1970-01-01
      • 2015-11-21
      相关资源
      最近更新 更多