0

我有如下所示的 html。

dataId下面是刚刚滚动的data-id。在这一点上,我想data-id接近这个元素。我采取了很多方法,不幸的是,没有一种方法奏效。

<div data-id='12345'>
   <p>hello there</p>
</div>
<div class='break'>
   <p>no man's land</p>
</div>
<div data-id='5678'>
   <p>Go for it</p>
</div>
<div class='test'>
   <p>just a test</p>
</div>
<div class='example'>
   <p>example</p>
</div>
<div data-id='5789'>
   <p>Last one</p>
</div>

js看起来像这样:

const firstDiv = $('div').attr('data-id["12345"]')
const nextDiv = firstDiv.next().attr('data-id');
// I am looking for the nextDiv to give me 5678
4

0 回答 0