admin管理员组

文章数量:1279015

Ive got this dropdown styled with bootstrap:

<li class="dropdown">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#" id="posuvnik">15min <strong class="caret"></strong></a>

    <ul class="dropdown-menu">
        <li> <a href="#" onclick="setPosuvnik(1)">15min</a> </li>
        <li> <a href="#" onclick="setPosuvnik(2)">1hod</a> </li>
    </ul>
</li>

and I want that dropdown menu to be rolled down on a page load, anyone know how to achieve that? thanks in advance :)

Ive got this dropdown styled with bootstrap:

<li class="dropdown">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#" id="posuvnik">15min <strong class="caret"></strong></a>

    <ul class="dropdown-menu">
        <li> <a href="#" onclick="setPosuvnik(1)">15min</a> </li>
        <li> <a href="#" onclick="setPosuvnik(2)">1hod</a> </li>
    </ul>
</li>

and I want that dropdown menu to be rolled down on a page load, anyone know how to achieve that? thanks in advance :)

Share Improve this question asked Dec 10, 2013 at 13:05 Julius ShadowAspect FlimmelJulius ShadowAspect Flimmel 1532 gold badges6 silver badges14 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

The dropdown is toggled with having the additional class 'open' added to the enclosing <li> element. So if you want to have it open on page loading:

<li class="dropdown open">

That will do the trick.

This little bit of jQuery script (I'm assuming you've loaded it becasue you're using Bootstrap) ought to do the trick. Once the DOM has loaded, it sends a click() to the dropdown toggle button.

$(document).ready(function () {
    $("#posuvnik").click();
});

There is probably a way to do it in straight CSS, but without seeing more of your code it's hard to know.

本文标签: javascriptbootstrap dropdown open on pageloadStack Overflow