最初にコメントの小さなコンテンツ(id = showmore_とforloopカウンタ)(30語)を表示しています。私はそれを隠し、同じループカウンタのid_content_のすべての内容を表示したいと思います。fadeToggle対応するdivとdjangoの正規表現
HTML:
<div class="comment"> Comments ({{discuss.get_comments|length}}):
{% for comment in discuss.get_comments %}
<div id="showmore_{{ forloop.counter }}">
{{ comment.commenter.get_full_name }} - {{ comment.body|truncatewords:30 }}...
<em>Read More</em>
</div>
<div id="more_content_{{ forloop.counter }}" style="display: none;">
{{ comment.body }}
</div>
<div>
{% for subcomment in comment.get_subcomments %}
<div>{{ subcomment.body|truncatewords:30 }</div>
{% endfor %}
</div>
{% endfor %}
</div>
のjQuery:
$(document).ready(function(){
$('div[id^="showmore_"]').click(function(){
$('div[id^="more_content_"]').fadeToggle();
});
});
私はすべて(例えばshowmoreまたはmore_content)に同じidを与え、すべての要素が非表示または示します。
私は何をしますか?
クラスの代わりにIDを与えてみてください。 IDはユニークです... – hansTheFranz