我正在尝试使用slideToggle以便在单击+符号时显示帖子信息。

您可以在以下测试博客上查看进度:http://noitsnotitsnotokay.tumblr.com/

到目前为止,这就是我对HTML和Javascript的要求(HTML部分会在每篇文章中重复,并且由于Tumblr defauts,我无法为每篇文章创建一个新类):

<div id="info">
<div class="pstinfo">
    <!-- info here -->
</div>
<span class="plsign">+</span>
</div>

<script>
$("div.pstinfo").hide();
$("span.plsign").click(function() {
$(this).parent().children("div.pstinfo").stop().slideToggle("slow");
return false;
});
</script>


正如您可能在测试博客中看到的那样,它在一篇文章中起作用,而在下一篇文章中,它不会一直打开。有没有什么办法解决这一问题?

最佳答案

我在代码中看到的主要问题是,每次对每个注释重复一次代码块。

因此,您有多个具有相同DIVID和具有相同绑定动作的多个<script>块。

喜欢:

{Block:Posts}
    <div><!-- // code in OP example (html+ID+Class+js) --></div>
{/Block:Posts}


那给你:

<div><!-- // code in OP example (html+ID+Class+js) --></div>
<div><!-- // code in OP example (html+ID+Class+js) --></div>
<div><!-- // code in OP example (html+ID+Class+js) --></div>
...


操作码为http://jsfiddle.net/gmolop/2fUjr/的错误示例



我建议先做,然后将其更改为:

{Block:Posts}
    <div><!-- // HTML code in OP example (only class, no ID) --></div>
{/Block:Posts}
<script> /* JS in OP example (outside the loop) */ </script>


那会给我们一些像:

<div><!-- // HTML code in OP example (only class) --></div>
<div><!-- // HTML code in OP example (only class) --></div>
<div><!-- // HTML code in OP example (only class) --></div>
<script>  /* JS in OP example (only once) */ </script>


使用建议格式的工作示例:http://jsfiddle.net/gmolop/2fUjr/1/

10-04 21:51
查看更多