javascript - 将 $(this) 传递给 jQuery 中的each() 回调

标签 javascript jquery callback this each

我有一个函数,通过在 jQuery 中的元素上调用each() 来调用。我想传递我调用each() 的元素作为参数。这是我现在拥有的代码的抽象版本,但是当我将 $(this) 传递给each() 的回调时,它会传递文档。

var myFunction = function(element){
    //do stuff with element
};

$('.element').each(myFunction($(this)));

我很乐意提供任何帮助,干杯!

最佳答案

$('.element').each(function(){
    myFunction($(this)); 
});

关于javascript - 将 $(this) 传递给 jQuery 中的each() 回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33896695/

相关文章:

javascript - React 测试库 waitForElementToBeRemoved 无法正常工作

php - 存储为成员变量的调用回调

firebase - flutter : How to implement a callback

Jquery 和 Rails 3 : Run controller action from js file?

c++ - 在 C++ 中使用回调函数抓取帧。它如何与类(class)交流?

javascript - ASP.NET - 如何更改 JSON 序列化的方式?

javascript - jquery scroll防止排队

php - AJAX 上传不起作用,它会重新加载整个页面

javascript - 当浏览器innerwidth <innerheight时使用jquery或js在网页上显示消息

javascript - 滚动时菜单事件类 - 部分边距问题