更改活动标签的jQuery

时间:2018-08-09 14:36:44

标签: javascript jquery tabs

嗨,我想用jquery更改活动标签 这是我的代码

那请怎么解决

<nav class="navbar navbar-inverse" role="navigation">
  <div class="container">

    <div class="navbar-header">

      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#top-navbar-1">
                            <span class="sr-only">Toggle navigation</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
      <a class="navbar-brand visible-xs" href="index.html">Titel</a>
    </div>
    <div class="collapse navbar-collapse" id="top-navbar-1">
      <ul id="collapsablenav" class="nav navbar-nav navbar-right">
        <li class="active dropdown hidden-xs">
          <a data-toggle="dropdown" href="#" class="dropdown-toggle"> <b class="caret"></b></a>
          <ul class="dropdown-menu">
            <li id="CDCDC">
              <a data-toggle="tab" href="#ABAB"></a>
            </li>
            <li class="divider"></li>
            <li class="active" id="testclocalisation"><a data-toggle="tab" href="#hometab">AZ</a></li>
          </ul>
        </li>
        <li class="active visible-xs"><a data-toggle="tab" href="#FFFF">F</a></li>
        <li id="testFFFFFF"><a data-toggle="tab" href="#DDDDD">D</a></li>
        <li id="testCCCCCC"><a data-toggle="tab" href="#CCCCCC">C</a></li>
        <li id="testBBBBB"><a data-toggle="tab" href="#BBBBB">B</a></li>
        <li id="testAAAAAA"><a data-toggle="tab" href="#AAAAA">A</a></li>
      </ul>
    </div>
  </div>

</nav>

那请怎么解决

1 个答案:

答案 0 :(得分:0)

function changeTab( newID ) { $('.navbar li').removeClass('active'); $('#' + newID ).addClass('active'); }

现在在某些事件上调用此函数,并传递要激活的li的ID。