gpt4 book ai didi

javascript - jquery论坛评论回复或 "quote"

转载 作者:行者123 更新时间:2023-12-03 11:02:17 24 4
gpt4 key购买 nike

我正在尝试创建论坛“引用”,就像大多数论坛上的回复一样,但我不知道如何正确从评论中选择项目,而且我也不知道如何选择动态生成的 ID 。

这是我的评论 HTML:

<div class="well well-white col-md-10 col-md-offset-1">
<div class="media">
<a class="pull-left" href="http://localhost/laravel/forum/public/user/5/profile">
<img class="media-object hidden-sm" src="http://localhost/laravel/forum/public/img/avatars/U0vq13KDiPa0C4Kftr7jfdsfsdf.jpg" height="42" width="42" />
</a>

<div class="media-body">
<h4 class="media-heading"></h4>

<p class="text-left "> <span class="label label-black">By :</span> <strong> <a href="http://localhost/laravel/forum/public/user/5/profile">@user</a>:</strong>

</p>
<div class="col-md-12 bbcomment">
<div class="comment-body">Comment goes here</div>
</div>
</div>

<i class="glyphicon glyphicon-calendar"></i>
2015-01-10 20:11:06
<a id="quote-4" class="btn btn-black btn-circle text-uppercase pull-right" href="#">
<span class="glyphicon glyphicon-share-alt"></span> quote
</a>
</div>
</div>

所以我的问题是:如何通过单击带有动态生成 ID 的链接(在本例中为“quote-4”)来选择“comment-body”类,以便我可以将其插入到我的 textaria 中(我知道如何插入它,我只是在选择正确的元素和使用动态生成的 ID 方面遇到问题)

谢谢

最佳答案

您只需要遍历 DOM(沿着链向上移动)并找到与您所拥有的相关的项目。在 JQuery 中:

$("#quote-4").click(function(){
var media_div = $($(this).parents().find(".media")[0]);
var comment_body = $(media_div.find(".comment-body")[0]);
});

关于javascript - jquery论坛评论回复或 "quote",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28028927/

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