twitter-bootstrap 在页面加载时打开引导下拉菜单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20495374/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
bootstrap dropdown open on pageload
提问by Julius ShadowAspect Flimmel
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 :)
我希望在页面加载时滚动下拉菜单,有人知道如何实现吗?提前致谢 :)
回答by Olly Hodgson
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.
这一点点 jQuery 脚本(我假设您已经加载它,因为您使用的是 Bootstrap)应该可以解决问题。一旦 DOM 加载完毕,它就会向下拉切换按钮发送一个 click() 。
$(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.
可能有一种方法可以在直接的 CSS 中做到这一点,但是如果没有看到更多的代码,就很难知道。
回答by Neocult
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:
通过将附加类“open”添加到封闭的 <li> 元素来切换下拉列表。因此,如果您想在页面加载时打开它:
<li class="dropdown open">
That will do the trick.
这样就行了。

