jQuery的追加订单? [英] jQuery Append order?

查看:158
本文介绍了jQuery的追加订单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一系列的意见,并在答复它们下面的评论。我用这个code追加评论的下方新的回复。

I'm creating a series of comments, with replies to the comments below them. I use this code to append the new reply underneath the comment.

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

这工作正常,如果只有一个评论回复,但如果有两点意见,让我们说注释1注释2和,注释1注释2将下产生。回复注释1将正常工作,但答复注释2将产生最后一个注释1下方的回复框。

This works fine if there's only one comment to reply to, but if there's two comments, let's say Comment1 and Comment2, Comment1 will be generated underneath Comment2. Replying to Comment1 will work fine, but replying to Comment2 would generate the reply-box underneath the last one in Comment1.

有什么办法,我让这个追加到评论说,它是从点击?

Is there any way for me to make it so that it appends to the comment that it's clicked from?

编辑:从我有生成的HTML标记

HTML markup generated from what I have.

<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没有做任何事情,但我想使这项工作,以单独的意见。

The other aspects of the JQuery don't affect it, only this one function creates sub-comments. So far, the unique thread IDs don't do anything, but I'm trying to make that work to seperate the comments.

推荐答案

使用jQuery 。经过()。使用这个你可以,你提供的。经过()函数,一前一后添加新元素。

use jquery .after(). using this you can add a new element after the one you provide for the .after() function.

所以可能做$('答案')。追加(),你应该做的$(本)。经过()。在这里,这个将指向元素被点击

so probably doing $('.answer').append() you should be doing $(this).after(). Here this will point to the element been clicked

这篇关于jQuery的追加订单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆