在普通的 JavaScript 中,我可以像这样移除数组的第一个元素并将其存储在变量中:
我该如何使用jQuery集合来实现同样的操作?
var rows = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var firstRow = rows.shift();
// now firstRow contains the first element of the original rows array,
// and rows contains the remaining elements.
我该如何使用jQuery集合来实现同样的操作?
var $rows = $('#some-table').find('> tbody > tr');
// ?
// ?
splice
方法。 - Saurabh Srivastavaslice()
,splice()
,:not(:first)
... - Rory McCrossan.get()
,然后就可以像shift()
一样应用任何数组方法。建议不要使用splice()
,因为它不会更新原始集合。 - A. Wolff:gt(0)
修饰符来从集合中省略第一个匹配项。 - Barmar