How do I keep my bootstrap submenu expanded on page load?

时间:2016-07-11 19:07:45

标签: javascript html css twitter-bootstrap

I am trying to make my sub menu item stay expanded and selected on page load using bootstrap, I am not sure how to do this in javascript. Here's my html: JSfiddle

 <ul class="ul-privacy-sidebar hidden-xs">
                        <li>
                            <a class="hidden-xs" href="#">
                                <span class="fa-stack">
                                            <i class="fa fa-circle fa-stack-2x ps-redorange"></i>
                                            <i class="mdi mdi-home fa-stack-1x fa-inverse"></i>
                                            </span> Privacy & Security
                            </a>
                        </li>
                        <li>
                            <a href="http://10.60.51.91/monster-responsive/global/www/privacy-policy/privacy-policy.html">
                                <span class="fa-stack">
                                            <i class="fa fa-circle fa-stack-2x ps-lt-green"></i>
                                            <i class="mdi mdi-file-document fa-stack-1x fa-inverse"></i>
                                            </span> Privacy Policy
                            </a>
                        </li>
                        <li>
                            <a href="#">
                                <span class="fa-stack">
                                            <i class="fa fa-circle fa-stack-2x ps-teal"></i>
                                            <i class="mdi mdi-bullhorn fa-stack-1x fa-inverse"></i>
                                            </span> Cookies, Ads & More
                            </a>
                        </li>
                        <li>
                            <a href="#">
                                <span class="fa-stack">
                                            <i class="fa fa-circle fa-stack-2x ps-orange"></i>
                                            <i class="mdi mdi-settings fa-stack-1x fa-inverse"></i>
                                            </span> Account Management
                            </a>
                        </li>
                        <li>
                            <a href="#">
                                <span class="fa-stack">
                                            <i class="fa fa-circle fa-stack-2x ps-pink"></i>
                                            <i class="mdi mdi-file fa-stack-1x fa-inverse"></i>
                                            </span> Resume Security
                            </a>
                        </li>
                        <li>
                            <a href="#">
                                <span class="fa-stack">
                                            <i class="fa fa-circle fa-stack-2x ps-redorange"></i>
                                            <i class="mdi mdi-alert-outline fa-stack-1x fa-inverse"></i>
                                            </span> Email Scams
                            </a>
                        </li>
                        <li class="active">
                            <a href="#faq-dropdow" class="list-group-item list-group-item-success" data-toggle="collapse" data-parent="#MainMenu">
                                <span class="fa-stack">
                                            <i class="fa fa-circle fa-stack-2x ps-teal"></i>
                                            <i class="mdi mdi-help fa-stack-1x fa-inverse"></i>
                                            </span> FAQs <i class="mdi mdi-chevron-down"></i>
                            </a>
                            <div class="collapse open visible-desktop" id="faq-dropdow">
                                <a href="#" class="list-group-item subitem active">About Monster</a>
                                <a href="#" class="list-group-item subitem">Data Collection</a>
                                <a href="#" class="list-group-item subitem">Data Usage</a>
                                <a href="#" class="list-group-item subitem">Data Sharing</a>
                                <a href="#" class="list-group-item subitem">Data Storage</a>
                                <a href="#" class="list-group-item subitem">Cookies & Tracking</a>
                                <a href="#" class="list-group-item subitem">Advertising</a>
                                <a href="#" class="list-group-item subitem">Account Profile & Management</a>
                                <a href="#" class="list-group-item subitem">Email & Other Communications</a>
                                <a href="#" class="list-group-item subitem">Safeguarding Data</a>
                                <a href="#" class="list-group-item subitem">Job Application Process</a>
                                <a href="#" class="list-group-item subitem">Privacy Standards</a>
                            </div>
                        </li>
                        <li>
                            <a href="#">
                                <span class="fa-stack">
                                            <i class="fa fa-circle fa-stack-2x ps-lt-green"></i>
                                            <i class="mdi mdi-email fa-stack-1x fa-inverse"></i>
                                            </span> Contact Us
                            </a>
                        </li>
                    </ul>

1 个答案:

答案 0 :(得分:0)

using the default bootstrap example: I only added class="open" to the parent li-item

HTML

Toggle navigation Brand

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
  <ul class="nav navbar-nav">
    <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
    <li><a href="#">Link</a></li>
    <li class="dropdown open">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
      <ul class="dropdown-menu">
        <li><a href="#">Action</a></li>
        <li><a href="#">Another action</a></li>
        <li><a href="#">Something else here</a></li>
        <li role="separator" class="divider"></li>
        <li><a href="#">Separated link</a></li>
        <li role="separator" class="divider"></li>
        <li><a href="#">One more separated link</a></li>
      </ul>
    </li>
  </ul>
  <form class="navbar-form navbar-left" role="search">
    <div class="form-group">
      <input type="text" class="form-control" placeholder="Search">
    </div>
    <button type="submit" class="btn btn-default">Submit</button>
  </form>
  <ul class="nav navbar-nav navbar-right">
    <li><a href="#">Link</a></li>
    <li class="dropdown active">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
      <ul class="dropdown-menu">
        <li><a href="#"/></li>
        <li><a href="#">Another action</a></li>
        <li><a href="#">Something else here</a></li>
        <li role="separator" class="divider"></li>
        <li><a href="#">Separated link</a></li>
      </ul>
    </li>
  </ul>
</div><!-- /.navbar-collapse -->