Twitter bootstrap 单击活动选项卡-twitter引导时关闭活动选项卡内容

Twitter bootstrap 单击活动选项卡-twitter引导时关闭活动选项卡内容,twitter-bootstrap,tabs,Twitter Bootstrap,Tabs,我正在使用twitter引导,我希望在单击活动选项卡时关闭活动选项卡内容 我使用此代码,但不起作用: $('#myTab a').click(function (e) { if ($(this).parent('li').hasClass('active')) { $($(this).attr('href')).removeClass('active'); $(this).parent('li').removeClass('active'); }

我正在使用twitter引导,我希望在单击活动选项卡时关闭活动选项卡内容

我使用此代码,但不起作用:

$('#myTab a').click(function (e) {
    if ($(this).parent('li').hasClass('active')) {
        $($(this).attr('href')).removeClass('active');
        $(this).parent('li').removeClass('active');
    } else {
        e.preventDefault();
        $(this).tab('show');
    }
});

这是可行的,但并不完美。我编辑bootstrap.js并替换它

  $(document).on('click.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) {
    e.preventDefault()
    $(this).tab('show')
  })
用这个

      $(document).on('click.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) {
  e.preventDefault();
      if($(this).parent('li').hasClass('active')){

       $( $(this).attr('href') ).removeClass('active'); 
        $(this).parent('li').removeClass('active');
       if ( $(this).parent('.dropdown-menu') ) {
              $(this).closest('li.dropdown').removeClass('active')
            }
        }
        else {
            e.preventDefault();
            $(this).tab('show');
        }
      })
但我还想知道,若下拉标签的子菜单是活动的,当我点击那个下拉标签时,类“活动”应该从那个下拉标签中移除,那个就是子菜单标签的内容


对不起,英语不好。

这对我很有用。删除“活动”类会更好

$('#myTab a').click(function (e) {
  if($(this).parent('li').hasClass('active')){
    $(this).removeClass('active')
    $( $(this).attr('href') ).removeClass('active');
  }
  else {
    e.preventDefault();
    $(this).tab('show');
  }
});
你可以在这里查一下

但是,如果需要在每个选项卡选择器上都执行此操作,请使用此jQuery选择器

$('a[data-toggle="tab"]').click(...

这对我来说毫无意义。。你能发布HTML吗?