50 lines
1.8 KiB
JavaScript
50 lines
1.8 KiB
JavaScript
/// <reference path="../js/jquery-3.6.0.min.js" />
|
|
/// <reference path="../js/utility.js" />
|
|
|
|
$.fn.tab = function (obj) {
|
|
obj = obj || {};
|
|
|
|
return this.each(function () {
|
|
var _this = $(this);
|
|
_this.data('tabparam', obj);
|
|
|
|
function switchPage(page) {
|
|
_this.children('div[data-page]').hide();
|
|
_this.children('div[data-page="' + page + '"]').show();
|
|
}
|
|
|
|
var titles = _this.children('.tab_header').children('[data-href]');
|
|
titles.each(function () {
|
|
var n_li = $(this);
|
|
if (n_li.attr('data-disabled') != null) {
|
|
return;
|
|
}
|
|
if (_this.data('inited'))
|
|
n_li.unbind('click');
|
|
n_li.click(function (e) {
|
|
var dfor = n_li.attr('data-href');
|
|
// invoke function
|
|
function next() {
|
|
if (typeof obj.onnext === 'function') {
|
|
obj.onnext(dfor);
|
|
}
|
|
titles.removeClass('selected');
|
|
n_li.addClass('selected');
|
|
//var dfor = n_li.addClass('selected').attr('data-href');
|
|
switchPage(dfor);
|
|
}
|
|
if (typeof obj.onclick === 'function') {
|
|
obj.onclick(n_li, next, _this.children('div[data-page="' + dfor + '"]'), dfor);
|
|
} else {
|
|
next();
|
|
}
|
|
});
|
|
});
|
|
//var datafor = titles.removeClass('selected').first().addClass('selected').attr('data-href');
|
|
// 由默认选中第一页修改为默认选中页面中指定的页,cl,2017/4/20
|
|
var datafor = _this.children('.tab_header').children('.selected').attr('data-href');
|
|
switchPage(datafor);
|
|
|
|
_this.data('inited', true);
|
|
});
|
|
}; |