jQuery不会找到动态创建的父级以将子元素绑定到

时间:2019-06-09 00:41:52

标签: jquery .net ajax

我有基本的反馈部分,人们可以在其中发布评论和评论回复。动态发布评论时,我无法回复它,因为它是动态生成的内容。页面刷新后,您可以回复评论。我尝试使用选择器参数,但无法使其正常工作。我的问题是,选择器应该是什么?什么ID?

@model FeedbackViewModel

<div class="comment-list">
    <div class="single-comment justify-content-between d-flex feedbackCom">
        <div class="user justify-content-between d-flex">
            <div class="thumb">
                <img src="~/images/blog/c3.jpg" alt="">
            </div>
            <div class="desc">
                <h5>
                    <a href="#">@Model.Name</a>
                </h5>
                <p class="date">@Model.CreatedOn.Value.ToLongDateString()</p>
                <p class="comment">
                    @Model.Comment
                </p>
            </div>
        </div>
        <div class="reply-btn">
            <div class="modal fade" id="replyModal" tabindex="-1" role="dialog" aria-labelledby="replyModalLabel" aria-hidden="true">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h5 class="modal-title" id="replyModalLabel">Submit Feedback</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <form id="send-reply-form" asp-action="AddReply" asp-controller="Business" asp-area="Business">
                                <input type="hidden" name="feedbackparentId" id="feedbackparentId"/>
                                <input type="hidden" name="businessid" value="@Model.Business.Id" />
                                @Html.AntiForgeryToken()

                                <div class="form-group form-inline">
                                    <div class="form-group col-lg-6 col-md-6 name">
                                        <input type="text" name="authorName" class="form-control col-form-label" id="name" placeholder="Enter Name" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter Name'">
                                    </div>
                                    <div class="form-group col-lg-6 col-md-6 email">
                                        <input type="email" name="email" class="form-control" id="email" placeholder="Enter email address" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter email address'">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <textarea class="form-control mb-10" rows="5" name="comment" placeholder="Message" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Message'"
                                              required=""></textarea>
                                </div>
                                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                <button type="submit" class="btn btn-primary">Send Feedback</button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            <button id="reply-button" type="button" class="btn btn-primary float-right" data-toggle="modal" data-target="#replyModal" data-id="@Model.Id">Reply</button>
        </div>
    </div>
</div>
<div class="comment-list left-padding" id="@Model.Id">
    @foreach (var reply in Model.Replies.OrderByDescending(r => r.CreatedOn))
    {
        <partial name="_ReplySectionPartial" model="reply" />
    }
</div>

评论html

@model FeedbackViewModel

<div class="single-comment replyComment justify-content-between d-flex">
    <div class="user justify-content-between d-flex">
        <div class="thumb">
            <img src="~/images/blog/c6.jpg" alt="">
        </div>
        <div class="desc">
            <h5>
                <a href="#">@Model.Name</a>
            </h5>
            <p class="date">@Model.CreatedOn.Value.ToLongDateString()</p>
            <p class="comment">
                @Model.Comment
            </p>
        </div>
    </div>
</div>

回复html

{{1}}

0 个答案:

没有答案