2014-08-28 65 views
0

我有一个带有选项卡的导航栏。一个标签在点击时应该变为活动状态,即css应该改变。另外以前的内容应该被隐藏和新的内容显示,但不I'ts表现得像我希望它:更改样式时显示和隐藏内容

http://jsfiddle.net/8qz78pkc/

我在做什么错?

SO需要这里的一些代码是有些JS:

$(document).ready(function(){ 
    $('.profileSubpage:gt(0)').hide(); 
    $(document).on('click','ul.profileTabs li',function(e){ 
     e.preventDefault(); 
     var number = $(this).index(); 
     $(".profileSubpage").hide().eq((this).index()).show(); 
     $(this).addClass("active").siblings().removeClass("active"); 
    }); 
}); 

回答

3

你在你的代码中的错误:

eq((this).index()) 

应该是:

eq($(this).index()) 
0

我已经修改你的代码。检查,

$(document).on('click','ul.profileTabs li',function(e){ 
     e.preventDefault(); 
     var number = $(this).index(); 
     $(".profileSubpage").hide(); 
     $(".profileSubpage:eq("+number+")").show(); 
     $(this).addClass("active").siblings().removeClass("active"); 
});