jquery插件的模板

/*!
 * jQuery plugin boilerplate
 */
;(function ( $, window, document, undefined ) {
    
    var pluginName = "defaultPluginName", //插件名称
        defaults = { //默认设置
            propertyName: "value"
        };

    // 插件的构造函数
    function Plugin( element, options ) {
        this.element = element;
        this.options = $.extend( {}, defaults, options) ;
        
        this._defaults = defaults;
        this._name = pluginName;
        
        this.init();
    }
    
    //原型方法
    Plugin.prototype = {
       //初始化
       'init' : function(){

       }
    };

    //创建jquery插件
    $.fn[pluginName] = function ( options ) {
        return this.each(function () {
       var pName = "plugin_" + pluginName;
//避免Plugin组件的重复实例化 if ( !$.data(this, pName) ) { $.data(this, pName, new Plugin(this, options) ); } }); } })( jQuery, window, document );
原文地址:https://www.cnblogs.com/langtao/p/3623080.html