码迷,mamicode.com
首页 > Web开发 > 详细

基于jquery的插件结构

时间:2015-01-24 11:34:00      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

(function ($) {
    /**
     * 创建dom
     * @param $this
     * @returns {boolean}
     */
    function createHtml($this) {

        _init($this);
    }

    /**
     * 初始化
     * @private
     */
    function _init($this) {

    }

    //public method
    var methods = {
        init: function (initOptions) {
            options = $.extend({}, $.fn.jqueryPluginName.defaults, initOptions);
            var $this = $(this);
            return this.each(function () {
                createHtml($this);
            });
        },
        destroy: function () {
            return this.each(function () {
            });
        },
        option: function (key, value) {
            if (arguments.length == 2)
                return this.each(function () {
                    if (options[key]) {
                        options[key] = value;
                    }
                });
            else
                return options[key];
        }
    }

    //插件的名字
    var methodName = "jqueryPluginName";

    var options = {};

    /**
     *  插件入口
     */
    $.fn.jqueryPluginName = function () {
        var method = arguments[0];
        if (methods[method]) {
            method = methods[method];
            arguments = Array.prototype.slice.call(arguments, 1);
        } else if (typeof method === "object" || !method) {
            method = methods.init;
        } else {
            $.error("Method(" + method + ") does not exist on " + methodName);
            return this;
        }
        return method.apply(this, arguments);
    }
    $.fn.jqueryPluginName.defaults = {
     
    };
})(jQuery);

  

基于jquery的插件结构

标签:

原文地址:http://www.cnblogs.com/ccc3/p/4245515.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!