我如何使用Tumblr元素与Javascript

How can I use Tumblr elements with Javascript?

本文关键字:Javascript 元素 Tumblr 何使用      更新时间:2023-09-26

如何使用Tumblr元素,如{Permalink}与Javascript?

为某些元素添加链接。

我的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}元素不能作为链接使用。当我点击链接所环绕的内容时,它会刷新页面

您不需要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的文章