我基於它們當前所在的位置對3個div進行排序。排序工作正常,但我努力獲取每個div的索引值。使用jquery對基於索引的div進行排序
的問題是,
- 當我點擊(下箭頭)的DIV 2它給我的指標值0,其中,因爲它應該給我1
- 如果我點擊的div 3(向上箭頭)它給人的 我0而不是2
HTML代碼:
<div class="flow-container">
<div class="flow-block">
<div class="sort-arrows">
<span class="fa fa-arrow-up" id="sort-up"></span>
<span class="fa fa-arrow-down" id="sort-down"></span>
</div>
<div class="flow-content" data-key="2yqz1jpdxwy2g434zyo8r7k6vml9n50d">
<h3 class="bg-primary">Div 1</h3>
</div>
</div>
<div class="flow-block">
<div class="sort-arrows">
<span class="fa fa-arrow-up" id="sort-up"></span>
<span class="fa fa-arrow-down" id="sort-down"></span>
</div>
<div class="flow-content" data-key="q2qlvpm98n7d2kejzx3g5jy41r6wzx0p">
<h3 class="bg-primary">Div 2</h3>
</div>
</div>
<div class="flow-block">
<div class="sort-arrows">
<span class="fa fa-arrow-up" id="sort-up"></span>
<span class="fa fa-arrow-down" id="sort-down"></span>
</div>
<div class="flow-content" data-key="q2qlvpm98n7d2kejzx3g5jy41r6wzx0p">
<h3 class="bg-primary">Div 3</h3>
</div>
</div>
</div>
演示 - https://jsfiddle.net/gvyoj63a/2/
任何幫助,如果高度讚賞。
您正在使用相同的ID對每個排序上/排序下來跨度。每個ID都必須是唯一的。 – gavgrif
是的。我會給予獨特的IDS。謝謝。 –