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 );
相關文章
相關標籤/搜索