nextAll() 中的回调函数

Posted

技术标签:

【中文标题】nextAll() 中的回调函数【英文标题】:Callback function in nextAll() 【发布时间】:2014-02-07 02:29:48 【问题描述】:

我只是想知道如何在 jquery 的nextAll 函数中有回调函数。

我试过了。

$('.selector').nextAll(function()  
  console.log("try");
);

但它不起作用。我阅读了jquery 网站上的文档,但我注意到没有回调示例。

我需要nextAll 而不是.each 来循环选择器的所有下一个后续元素并获取每个后续​​元素的右边距,然后将它们动画到右边。我试过了,

$('.selector').nextAll().animate( right: (margin_right-100)+'px', 500);
//I am getting the logic here because it animates all the succeeding 
//element but the problem is that I had to replace the 
//`margin_right` variable because the elements next to the 
//selector differs on margin-right.

有什么意见吗?

【问题讨论】:

【参考方案1】:

你都试过了吗?

$('.selector').nextAll().each(function()  
  console.log(this);
);

【讨论】:

是的,我确实尝试了这两种方法,它现在是我的代码的当前设置,当我将您的答案红色并将其与我迄今为止尝试过的进行比较时,我注意到我缺少一些值。但无论如何谢谢。这里需要澄清一下,我们可以不写成nextAll(function() )吗?

以上是关于nextAll() 中的回调函数的主要内容,如果未能解决你的问题,请参考以下文章

js中的回调函数,什么是回调函数?

JS中的 回调函数(callback)

如何在外面引用js中ajax回调函数中的值

进程池中的回调函数

java里面,c里面都有回调函数,回调函数都是啥东西啊???

jquery 中的回调函数,回调函数(callback)是什么?