我想总是得到最后一个数据ID。 即使我在dinamically中添加更多带有更多data-id的类。
如何获取最后一个data-id值而不是第一个?
$( document ).ready(function() {
$(window).scroll(function() {
if ($(window).scrollTop() >= $(document).height() - $(window).height() - 200){
var variable = $('.report').data("id");
alert(variable);
}
});
});
// how to get data from the last one only?
<li class="report" data-id="602532">Report inappropriate</li>
<li class="report" data-id="602530">Report inappropriate</li>
<li class="report" data-id="602529">Report inappropriate</li>
<li class="report" data-id="602531">Report inappropriate</li>
<li class="report" data-id="602575">Report inappropriate</li>
<li class="report" data-id="602557">Report inappropriate</li>
<li class="report" data-id="602574">Report inappropriate</li>
答案 0 :(得分:0)
尝试:
$( document ).ready(function() {
var variable = $('.report').last("id");
alert(variable);
});