这个代码是从深度android门户站上扒下来的,我用了,非常的好用。特此记录下,以备不时之需!此代码是基于JQuery的,所以使用的时候要先调用jQuery文件。
//simple class
function Class(p) {
function _(){p.init && p.init.apply(this, arguments)}
_.prototype = p;
return _;
}
// the class of tab
var tab = Class({
running : 0,
init : function(opt){
this.opt = {
event : 'mouseover',
animate : false
};
$.extend(this.opt, opt);
this.go();
opt.otherHandler && opt.otherHandler(this);
},
go : function() {
var anim = this.opt.animate,
ev = this.opt.event,
self = this,
tabs = this.opt.tabs,
layers = this.opt.layers;
tabs.bind(ev, function(){
var i = tabs.index(this);
self._display(i);
});
},
_display : function(i) {
var cls = this.opt.tabs_on_class;
this.opt.tabs.removeClass(cls).eq(i).addClass(cls);
this.opt.layers.hide().eq(i).show();
}
});
new tab({
tabs : $('#nav_tabs>span a'),
layers : $('#nav_list>div'),
tabs_on_class : "cu"
});
//注:需要在body里调用,且在你的tabs所有的代码后面