获取 array.length 中的第一个数字

Get the first number in array.length

本文关键字:第一个 数字 array length 获取      更新时间:2023-09-26

我有一个动态创建的数组。我正在尝试添加一个 span 标签,该标签会说类似 1 of 20 items 然后我可以浏览它们。

所以在第二个span标签中,我有

$('.count_wrap--num').text(theData.length);

这给了我数组中的总数。
我的第一个span标签,我想在 1 看起来像:

$('.count_wrap--numOf').text(theData.length);
但是,它

再次给了我完整的数字,我怎样才能得到它,所以第一项是 1?我已经尝试过$('.count_wrap--numOf').text('1');但索引从 0 开始,所以在导航时计数很奇怪

尝试使用计数器。因此,每次他们单击下一步按钮时,它都会递增计数器,然后在 html 中显示该计数器。

Javascript:

var counter=1;
$('#nextBtn').click(function() { counter++; });
$('.count_wrap--num').text(theData.length);
$('.count_wrap--numOf').text(counter);

这是示例的小提琴https://jsfiddle.net/fawxngcL/1/