lyg
2025-03-04 72bbec1590f85974d369ce7aeaa05be8905672a0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
mbui.define([], function (exports) {
  var Tab = function () {
    this.config = {
      elem: null,
      trigger: 'click',
      ontab: null
    };
  };
 
  // 初始化Tab
  Tab.prototype.init = function (options) {
    var that = this;
    $.extend(true, that.config, options);
    var elem = $(that.config.elem);
    var tabs = elem.find('.mbui-tab-title li');
    var contents = elem.find('.mbui-tab-content .mbui-tab-item');
 
    tabs.on(that.config.trigger, function () {
      var index = $(this).index();
      tabs.removeClass('active');
      contents.removeClass('mbui-tab-show');
      $(this).addClass('active');
      contents.eq(index).addClass('mbui-tab-show');
 
      // 执行回调函数
      if (typeof that.config.ontab === 'function') {
        that.config.ontab(index, $(this));
      }
    });
  };
 
  // 导出Tab模块
  exports('tab', function (options) {
    var tab = new Tab();
    tab.init(options);
  });
});