0

我喜欢这些 div 块中的 8 个,我想知道是否单击了 8 个列表中的最后两个 a。这将是动态的,所以现在可能是 8,以后可能是 20,所以代码需要知道它的最后两个不是 7 或 8。

<div class="seven columns offset-by-one">
  <h1>
    Joshua F. Schwartz
  </h1>
  <h2>
    Position
  </h2>
  <p>
    Etiam lacus dui, sollicitudin non pulvinar nec, fringilla commodo mauris. Nunc orci enim, pellentesque porta malesuada eu, ornare vel lectus. In venenatis nisl ut lorem ultricies semper. Duis vitae turpis nec tortor dignissim tempor. Phasellus et elit et. <a href="">Read More</a>
  </p>
</div>
4

2 回答 2

0

你可以试试这样的。

$('a').click(function () {
    $(this).parent().parent().data('aClicked',true);
});

然后下次当您访问 div 或单击时,只需检查是否为真。

于 2013-04-15T19:39:11.987 回答
0

您可以使用 jQuery index() 方法:

function isLastTwo(element) {
  // Get the total <div> tags
  var length = $("div.columns.offset-by-one").length;

  // Compare the index of current element to the length
  return $(element).index() >= (length - 2);
}
于 2013-04-15T19:42:33.947 回答