我看到的一些开发jQuery插件的教程和示例往往会返回

this.each(function () {
    //Plugin code here
});

at the end of the function that instantiates the plugin but I have yet to see any reasoning behind it, it just seems to be a standard that everyone follows. Can anyone enlighten me as to the reasoning behind this practice?

Edit: For clarification my question was not about why to return this, but rather why the plugin should return this.each.

推荐答案

使用 Select 器($('.myclass'))过滤元素时,它可以匹配多个元素

Jquery相关问答推荐

使用带有 bootstrap 验证的 Ajax 函数时出现问题

jQuery:如何动态检测窗口宽度?

如何滚动到jQuery中的元素?

我如何从 ACE 编辑器中获得价值?

使用 jQuery 将行添加到表的 tbody

如何在 JQuery UI 自动完成中使用 source:function()... 和 AJAX

确定 JavaScript 值是否为整数?

scrollIntoView 是否适用于所有浏览器?

动画元素变换旋转

Select 除第一个之外的所有子元素

jQuery.extend 和 jQuery.fn.extend 的区别?

jQuery UI 工具提示不支持 html 内容

如何将数组传递给 jQuery .data() 属性

如何使用 jquery 动态更改 iframe 中的内容?

与 C# HashSet 等效的 JavaScript 是什么?

jQuery:如何找到父母的特定子元素?

如何淡出显示:inline-block

组织 jQuery/JavaScript 代码的最佳方式 (2013)

bootstrap 日期和时间 Select 器

JavaScript 在 DOM 中移动元素