gpt4 book ai didi

jQuery 追加顺序?

转载 作者:行者123 更新时间:2023-12-01 08:05:09 27 4
gpt4 key购买 nike

我正在创建一系列评论,并回复其下方的评论。我使用此代码在评论下方 append 新回复。

$(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;
});

如果只有一条评论需要回复,则效果很好,但如果有两条评论,比如 Comment1 和 Comment2,Comment1 将在 Comment2 下方生成。回复 Comment1 可以正常工作,但回复 Comment2 会在 Comment1 的最后一个回复框下方生成回复框。

我有什么方法可以将其 append 到从中单击的评论中吗?

编辑:根据我所拥有的内容生成 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 的其他方面不会影响它,只有这一个函数会创建子注释。到目前为止,唯一的线程 ID 没有做任何事情,但我正在尝试使其能够分隔评论。

最佳答案

使用jquery .after() 。使用它,您可以在为 .after() 函数提供的元素之后添加一个新元素。

所以可能在执行 $('.answer').append() 时,您应该执行 $(this).after() 。这里 this 将指向被点击的元素

关于jQuery 追加顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17128759/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com