当前位置 : 主页 > 网页制作 > JQuery >

jQuery 插件格式

来源:互联网 收集:自由互联 发布时间:2021-06-15
(function (factory) { if (typeof define === ‘function‘ define.amd) { define([‘jquery‘], factory); } else { factory(jQuery); } }(function ($) { function myShowOrHide($element, options) { this.$element = $element; this._defaults = { s

(function (factory) {
  if (typeof define === ‘function‘ && define.amd) {
    define([‘jquery‘], factory);
  } else {
    factory(jQuery);
  }
}(function ($) {

  function myShowOrHide($element, options) {
    this.$element = $element;
    this._defaults = {
      size: 3,
      status: ‘hide‘
    };
    this.options = $.extend({}, this._defaults, options || {});
    this.init();
  }

  myShowOrHide.prototype = {
    init: function () {

    },
    soh: function () {

    }
  }
};

$.fn.myShowOrHide = function (options, param) {
  return this.each(function () {
    var instance;
    instance = $.data(this, ‘myShowOrHide‘);
    if (!instance) {
      instance = new myShowOrHide(this, options);
      $.data(this, ‘myShowOrHide‘, instance);
    }
    if ($.type(options) === ‘string‘) {
      return instance[options](param);
    }
  });

}

return this;}));

网友评论