jQuery插件模板 [英] jQuery plugin template

查看:65
本文介绍了jQuery插件模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经找到了用于创建jQuery插件的模板 http://stefangabos. ro/jquery/jquery-plugin-boilerplate-revisited/

I've found this template for creating jQuery plugin http://stefangabos.ro/jquery/jquery-plugin-boilerplate-revisited/

但是我不理解代码,为什么我们将pluginName声明为jQuery对象的方法,然后又将pluginName声明为对象$ .fn的方法,为什么呢?

But I don't understand in code, why we declare pluginName like a method of jQuery object and then we declare pluginName like a method of object $.fn why we did that?

推荐答案

将插件添加到$使您可以编写:

Adding the plugin to $ enables you to write:

var $el = $(".myselector");
$.myplugin($el, {
  some: "option",
  another: "one"
});

将插件添加到$.fn使您可以编写:

Adding the plugin to $.fn enables you to write:

$(".myselector").myplugin({
  some: "option",
  another: "one"
});

这篇关于jQuery插件模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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