如何为jQuery选择器创建自定义函数 [英] How to make custom function for jQuery selector

查看:81
本文介绍了如何为jQuery选择器创建自定义函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将自定义函数附加到jQuery选择器?看起来像:

How does one go about making a custom function to append to the jQuery selector? Something that would look like:

$('.my_class').my_function();


推荐答案

您想要将函数添加到 jQuery.fn (这是对jQuery对象原型的引用)。有关详细信息,请查看:

You want to add the function to jQuery.fn (which is a reference to the jQuery object prototype). For more details check out:

http:// docs.jquery.com/Plugins/Authoring

示例\ stub:

(function($){
  $.fn.my_function = function(){ ... };

})(jQuery);

这篇关于如何为jQuery选择器创建自定义函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆