我有一个可以在 dom 中重新排列的单词列表,我需要按特定顺序抓取它们中的每一个。我已经(有点)计算了我需要它们的顺序,并使用 jQuery 将该数字用作它们的 ID。
我的问题是如何从编号最低的 ID 开始并以最高编号结束它们中的每一个?
html 看起来像这样:
<span class="chosenword" id="577.9848041534424" style="position: absolute; top: 320px; left: 442.9999694824219px; z-index: 1;">Word!</span>
JS是这样的:
$('.chosenword').each(function(){
var position = $(this).position();
var id = ((position.left) * (position.top));
$(this).attr('id', id);
var chosenword = $(this).html();
$('#chosenwords').append(chosenword);
$('#chosenwords').append(" ");
});
请注意,我实际上并没有抓取具有 Id 的环绕 Span,因此在抓取它们之后我无法真正重新排列它们,至少我不想这样做。
有任何想法吗?