我一直在用头撞墙试图让这项工作有一段时间了。我正在尝试将评论正文缩短为一行以进行紧凑的评论预览。我正在使用 jquery .each 函数来遍历我的线程评论系统中的每个 .cbody (评论正文),并将其放在 chead 内的 cshort div 中。它应该可以工作,但我不能在第一行选择 cshort 类。非常感谢任何帮助。据我所见,我的 jquery 应该是这样的:
$('.cbody').each(function(Ind1){
var str = $(this).text();
$(this).parent().siblings('.chead').next('.cshort').html(str);
});
});
这是评论的html:
<ul>
<li>
<div id="23">
<a name="23">
</a>
<div class="chead">
<a href="#" class="unord">
<img src="images/plus.gif" border="0">
</a>
<a href="userinfo.php?user=muuuuuuuu">
<img src="include/avatar/n.jpg" border="0">
</a>
<span style="display: none;" class="uname">
usersname
</span>
,
<span class="cshort">
</span>
<span class="votes_up" id="votes_up23">
2
</span>
-
<span class="votes_down" id="votes_down23">
0
</span>
<span class="vote_buttons" id="vote_buttons23">
<a href="javascript:;" class="vote_up" id="23">
</a>
<a href="javascript:;" class="vote_down" id="23">
</a>
</span>
</div>
<div class="cbody">
<br>
The comment text funny lol
</div>
<a style="display: none;" href="#" class="reply" id="23">
Reply
</a>
<a style="display: none;" href="#21" class="cparent">
Parent
</a>
</div>
</li>
</ul>