Tag: 每一个

计算具有特定类的元素数量,然后添加一个对其进行编号的ID

我对此非常陌生,只想把其他post的片段拼凑起来。 我不确定如何计算页面上的元素数量,然后添加一个类来区分它们的数字。 $(document).ready(function(){ $(‘.item’).each(function (e) { $(this).addClass(‘count’ + e); }); }); 输出到:

使用jQuery .each()时,是否可以使用非匿名函数?

我有这个代码块,我发现特别长,难以理解:调用堆栈充满了隐含的函数和隐含的添加到它的参数。 换句话说,我想通过将每个中调用的函数与每个函数分开来澄清我的代码。 看那个例子: $(xml).find(‘group’).each(function () { var groupName = $(this).attr(‘name’); // There is here around 100 lines of codes I would like to split in // at least five functions, And I’m sure it is possible to use named functions // instead of implicit ones, no ?

完成/完成后如何在$ .each json数组上使用.promise()。done()?

我想在$ .each完成后执行一些操作。 $.each(someArray, function(index, val) { //———some async ajax action here per loop ——— $.ajax({…}).done(function(data){…}); }.promise().done(function(){…}); //<——-error here can't use with $.each 不是每个jQuery函数都有promise()吗? 我怎么知道$ .each数组什么时候完成? 我可以将someArray更改为$ someArray来使用它吗?