选择最后一个孩子
问题描述:
我想知道如何通过点击链接来获得最后一个孩子的提醒。选择最后一个孩子
<h3 id="comment:5" class="myclass">
这是多远我得到:
$('#lastcomment').click(function() {
alert('Handler for .click() called.');
});
我的目的是通过点击链接,跳转到最后一个注释。我猜,第一步可能会发出警报。这样我可以看到评论的最后一个孩子。
任何帮助,非常感谢。
答
$("#lastcomment").click(function() {
var lastComment = $("h3[id^=comment]:last");
alert(lastComment.attr("id"));
}
答
你可以使用jQuery的:last
选择器。但我需要看到更多的HTML来使一些工作...
答
因此,你有一个链接,你想要去一个页面上的最后一个评论?为何不给评论评论-12(例如)的ID,那么就改变你的锚relfect此:
<a class="myclass" href="#comment-12" id="last-comment"> </a>
如果你想做到这一点在JavaScript中,是这样的:
$('#lastcomment').click(function() {
var numComments = $(".comments").length; // Assuming your comments have a class
window.location = window.location.href + "#" + $(".comments").eq(numComments).attr("id");
});
你能给的要提醒什么的例子吗? – 2010-09-22 11:18:11
TI想要提醒最新评论。在这种情况下评论:9。 – Faili 2010-09-22 11:19:39