jquery 插件 模板
来源:互联网 发布:usb网络共享用不了 编辑:程序博客网 时间:2024/05/21 22:20
// jQuery Plugin Boilerplate// A boilerplate for jumpstarting jQuery plugins development// version 1.1, May 14th, 2011// by Stefan Gabos// remember to change every instance of "pluginName" to the name of your plugin!(function($) { // here we go! $.pluginName = function(element, options) { // plugin's default options // this is private property and is accessible only from inside the plugin var defaults = { foo: 'bar', // if your plugin is event-driven, you may provide callback capabilities // for its events. execute these functions before or after events of your // plugin, so that users may customize those particular events without // changing the plugin's code onFoo: function() {} } // to avoid confusions, use "plugin" to reference the // current instance of the object var plugin = this; // this will hold the merged default, and user-provided options // plugin's properties will be available through this object like: // plugin.settings.propertyName from inside the plugin or // element.data('pluginName').settings.propertyName from outside the plugin, // where "element" is the element the plugin is attached to; plugin.settings = {} var $element = $(element), // reference to the jQuery version of DOM element element = element; // reference to the actual DOM element // the "constructor" method that gets called when the object is created plugin.init = function() { // the plugin's final properties are the merged default and // user-provided options (if any) plugin.settings = $.extend({}, defaults, options); // code goes here } // public methods // these methods can be called like: // plugin.methodName(arg1, arg2, ... argn) from inside the plugin or // element.data('pluginName').publicMethod(arg1, arg2, ... argn) from outside // the plugin, where "element" is the element the plugin is attached to; // a public method. for demonstration purposes only - remove it! plugin.foo_public_method = function() { // code goes here } // private methods // these methods can be called only from inside the plugin like: // methodName(arg1, arg2, ... argn) // a private method. for demonstration purposes only - remove it! var foo_private_method = function() { // code goes here } // fire up the plugin! // call the "constructor" method plugin.init(); } // add the plugin to the jQuery.fn object $.fn.pluginName = function(options) { // iterate through the DOM elements we are attaching the plugin to return this.each(function() { // if plugin has not already been attached to the element if (undefined == $(this).data('pluginName')) { // create a new instance of the plugin // pass the DOM element and the user-provided options as arguments var plugin = new $.pluginName(this, options); // in the jQuery version of the element // store a reference to the plugin object // you can later access the plugin and its methods and properties like // element.data('pluginName').publicMethod(arg1, arg2, ... argn) or // element.data('pluginName').settings.propertyName $(this).data('pluginName', plugin); } }); }})(jQuery);
使用方法
$(document).ready(function() { // attach the plugin to an element $('#element').pluginName({'foo': 'bar'}); // call a public method $('#element').data('pluginName').foo_public_method(); // get the value of a property $('#element').data('pluginName').settings.foo;});
0 0
- jQuery插件---jTemplates(模板)
- jQuery 插件模板
- JQuery插件、模板
- jQuery插件---jTemplates(模板)
- jquery 插件 模板
- jQuery开发插件模板
- JQuery模板插件-jquery.tmpl的使用
- jQuery模板插件--jQuery tmpl初识
- jQuery的一个小插件模板输入
- Jquery 模板数据绑定插件 使用方法
- jquery模板插件jTemplates代替拼html
- jquery - 日历插件(自定义模板的日历插件)
- 一个jQuery模板插件的测试例子--boilerplate模板插件测试
- 推荐好用的Jquery模板插件Jtemplate
- 推荐好用的Jquery模板插件Jtemplate
- jTemplates是javascript的模板引擎,基于jquery的插件
- 推荐好用的Jquery模板插件jTemplates
- 编写一个简单的 jQuery 插件(模板)
- 在应用程序级别以外使用注册为 allowDefinition='MachineToApplication' 的节是错误的解决办法
- pig-on-tez or hive-on-tez 报错
- Java RTTI和反射机制
- ios kvc
- linux vmware view client修改窗口大小
- jquery 插件 模板
- Android 4.0硬件加速及绘制技巧
- mantis实验提高篇
- MFC右键菜单
- 支付宝
- 程序员从初级到高级的蜕变
- H5学习之旅-H5的基本标签(2)
- 一晚上的成果
- hive之HQL用法案例