【发布时间】:2013-06-12 07:11:19
【问题描述】:
我正在创建一系列 cmets,并对它们下方的 cmets 进行回复。我使用此代码将新回复附加到评论下方。
$(document).on('click', '.sub-reply1-send', function() {
var reply = $('textarea[name=comment-reply]').val();
$('.sub-reply1, .sub-reply1-textarea, .sub-reply1-send').slideUp(250).remove();
$('.answer').append("<div class='comment-sub-reply' style='display:none'>" + reply + "</div>");
$('.comment-sub-reply').slideDown(250);
subreply_visible = false;
});
如果只有一条评论要回复,这很好用,但如果有两个 cmets,假设 Comment1 和 Comment2,Comment1 将在 Comment2 下生成。回复 Comment1 可以正常工作,但回复 Comment2 会在 Comment1 的最后一个下方生成回复框。
我有什么方法可以让它附加到点击它的评论中吗?
编辑:根据我所拥有的生成 HTML 标记。
<div id="right-bar" class="flexcroll" style="display: block;">
<div class="question" style="display: block;">
<div class="question-content">What is the significance of this section?</div>
</div>
<div class="answer" style="display: block;">
<div class="question-answer" style="" id="thread1">This is not a test
<img class="reply" src="reply.png" />
</div>
<div class="question-answer" style="" id="thread0">Test
<img class="reply" src="reply.png" />
</div>
<div class="comment-sub-reply" style="">Another Test</div>
<div class="comment-sub-reply" style="">Still underneath Test</div>
<div class="comment-sub-reply" style="">This isn't a test either, but it's appearing under test</div>
<div class="sub-reply1" style="">
<textarea class="sub-reply1-textarea" name="comment-reply" style=""></textarea>
<div class="sub-reply1-send" style=""></div>
</div>
</div>
<div id="comment">
<form name="commentForm">
<textarea type="text" name="comment" id="answer-text-input" align="top" class="flexcroll" style="display: block;"></textarea>
</form>
<div id="button" style="display: block;"></div>
</div>
</div>
JQuery 的其他方面不影响它,只有这个函数创建子 cmets。到目前为止,唯一的线程 ID 并没有做任何事情,但我正在努力使这项工作分离 cmets。
【问题讨论】:
-
当您单击 .sub-reply1-send 时会显示代码,并且您将在同一 .question-answer 下附加评论。不应该点击#thead1 的.reply 在#thread1 和#thread0 之间创建一个.sub-reply1 吗?
-
我想我对你所说的“cmets”感到困惑。您是指问题答案还是评论子回复?至于“我有什么办法可以使它附加到单击它的评论中吗?”请定义什么评论,你点击了什么?因为代码似乎将注释附加到 .answers div。这不是你想要的吗?