动态下拉菜单使用php与twitter bootstrap

时间:2013-04-17 14:18:36

标签: php html twitter-bootstrap

感谢您阅读...我有2层导航。根据好,坏和评论计数对内容进行排序。如果用户点击好,它将带来另一个导航,按时间排序内容。比如今天,过去一周,过去一个月。

我可以使用class='active'添加$_SERVER['PHP_SELF']但是twitter bootsrap下拉菜单没有简单class='active'这很复杂。我无法提出解决方案。我应该用吗?的foreach?我不知道。请参阅代码中的html命令。这是我的代码。

<ul class="nav nav-tabs">
        <li <?php if (basename($_SERVER['PHP_SELF']) == '/?Top'): ?> class="active"<?php endif; ?>><a href="/?Top">Top Content</a></li> 
        <li <?php if (basename($_SERVER['PHP_SELF']) == '/?Bad'): ?> class="active"<?php endif; ?>><a href="/?Bad">Bad Content</a></li>
        <li <?php if (basename($_SERVER['PHP_SELF']) == '/?Comments'): ?> class="active"<?php endif; ?>><a href="/?Comments">Most Commented</a></li>
<!-- It's confusing me when It comes here... because as you see active option is not li tag. it's bunch of html code and also any url bellow can ben any of those up -->
          <li class="dropdown">
            <a class="dropdown-toggle" data-toggle="dropdown" href="#"><i class="icon-time"></i> Today <b class="caret"></b></a>
            <ul class="dropdown-menu">
              <li><a href="URL=week" />Last 1 Week</a></li>
              <li><a href="URL=month" />Last 1 Month </a></li>
              <li><a href="URL=all" />All</a></li>
            </ul>
          </li>
    </ul>

html推荐:当它来到这里时让我很困惑...因为你看到活跃的li不是它的一堆html代码,而且下面的任何url也可以是任何一个

1 个答案:

答案 0 :(得分:1)

您可以在子项下拉列表中使用外部"active" li类("dropdown"}和另一个"active"类。{/ p>

这是一个例子

<ul class="nav nav-tabs">
    <li class=""><a href="#">Home</a></li>
    <li><a href="#">Help</a></li>
    <li class="dropdown active">
      <a href="#" data-toggle="dropdown" class="dropdown-toggle">Dropdown <b class="caret"></b></a>
      <ul class="dropdown-menu">
        <li><a href="#">Action</a></li>
        <li class="active"><a href="#">Another action</a></li>
        <li><a href="#">Something else here</a></li>
        <li class="divider"></li>
        <li><a href="#">Separated link</a></li>
      </ul>
    </li>
  </ul>

JSBin

中的现场演示