在改变风格时显示和隐藏内容

时间:2014-08-28 08:18:51

标签: jquery twitter-bootstrap

我有一个带标签的导航栏。单击选项卡时应该变为活动状态,即css应该更改。此外,之前的内容应该被隐藏并显示新内容,但我的表现并不像我想要的那样:

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");
    });
});

2 个答案:

答案 0 :(得分:3)

您的代码中有错误:

eq((this).index())

应该是:

eq($(this).index())

答案 1 :(得分: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");
 });