script部分
function?Tab(option){
? ? ? ? this.root=$(option.root);
? ? ? ? this.tabTag=this.root.find('#tabon li');
? ? ? ? this.hidden=this.root.find('.hidden');
? ? ? ? this.init();???
}
Tab.prototype={//prototype對象是實現(xiàn)面向?qū)ο蟮闹匾獧C制
? ? ? ? ?init:function(){
? ? ? ? ? ? ? ? ? ? var?that=this;
? ? ? ? ? ? ? ? ? ? ? ? ? ? this.tabTag.each(function(i){ ? ? ? ? //each()方法為每個匹配元素規(guī)定要運行的函數(shù)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? $(this).click(function(){
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? that.tabTag.removeClass("cur");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? $(this).addClass('cur');
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?that.hidden.eq(i).show().siblings().hide();
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? })?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?})?????????
? ? ? ? ? ?}??
}
$(function(){
new?Tab({'root':$('.tab')});
//root選擇器選取文檔的根元素嫩絮,new會創(chuàng)建pre的對象丛肢,沒有new的話就沒有任何可返回的值或?qū)ο笪Х剩允莡ndefined。
})