我的脚本中有一部分循环遍历列表中的元素数量,并获取信息然后将其放入不同的 div 中。由于某种原因,第一个 each 循环不会计算其索引。我尝试了几种不同的方法来做到这一点,但似乎都没有奏效。
这是脚本:
//check each Item for a List
if ($(obj).has('> ul')) {
// Second Level Lists
$(obj).find('> ul').each(function (index, obj) {
// Create Second Level Divs
baseElement.append(
'<div class="level" id=' + index +
' style="color:' + settings.startColor + ';background:' +
settings.startBg +';font-size:' + settings.baseFont +
'px;position:absolute;width:100%;height:100%;"></div>'
);
// Second Level List Items
$(obj).find('> li').each(function (i, obj) {
$('.level#2').append(
"<span>" +
$(obj).find('>:first-child').text() +
"</span>"
);
});
});
}
我需要让它计数,并将每个创建的 div 命名为从上一个开始的数字......我已经拿起了我的大脑,不知道可能出了什么问题。