我如何使用带有 Javascript 的 Tumblr 元素?

How can I use Tumblr elements with Javascript?

如何将 Tumblr 元素(例如 {Permalink})与 Javascript 一起使用?

专门为某些元素添加link。

我的javascript:

<script type="text/javascript">

        $('.takemethere').each(function() {
  var link = $(this).html();
  $(this).contents().wrap('<a href="{Permalink}"></a>');
});

    </script>

HTML:

{block:Photo}

<div class="takemethere"><img src="{PhotoURL-500}" width="50px" height="50px" alt="{PhotoAlt}"/></div>

{block:caption}{Caption}{/block:Caption}

{/Block:Photo}

{Permalink} 元素不能用作 link。当我点击我包裹link的内容时,它只是刷新页面。

您不需要 javascript,直接在您的主题中使用 {Permalink} 主题运算符:

{block:Photo}

<a href="{Permalink}">
  <img src="{PhotoURL-500}" width="50px" height="50px" alt="{PhotoAlt}"/>
</a>

{block:caption}{Caption}{/block:Caption}

{/Block:Photo}

参考:https://www.tumblr.com/docs/en/custom_themes#posts