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对象是实现面向对象的重要机制
init:function(){
var that=this;
this.tabTag.each(function(i){ //each()方法为每个匹配元素规定要运行的函数
$(this).click(function(){
that.tabTag.removeClass("cur");
$(this).addClass('cur');
that.hidden.eq(i).show().siblings().hide();
})
})
}
}
$(function(){
new Tab({'root':$('.tab')});
//root选择器选取文档的根元素,new会创建pre的对象,没有new的话就没有任何可返回的值或对象,所以是undefined。
})
网友评论