Bootstrap 3使用Javascript打开页面加载下拉 [英] Bootstrap 3 Open Drop Down on page load with Javascript
问题描述
我无法在页面加载时打开此下拉菜单。谁能帮忙?
Bootrap 3上的文档在这里: http://getbootstrap.com/javascript/#dropdowns
I can't seem to open this dropdown menu on page load. Can anyone help? Documentation on Bootrap 3 is here: http://getbootstrap.com/javascript/#dropdowns
我尝试过,但似乎不起作用
I tried this but it doesn't seem to work
$('#myDropdown').dropdown()
最终,我需要能够打开一个可折叠菜单中的下拉菜单。例如,我想在用户点击菜单按钮后打开第一个下拉菜单。但我不能让它工作。
Ultimately, I need to be able to open a drop down that is inside a collapsible menu. For example, I want to open the first down down menu after the user clicks on the menu button. but I can't get it to work.
编辑:当显示导航栏时,使用定时器等待1毫秒,然后再调用.dropdown('toggle )。喜欢这个。
When the navbar is shown, use a timer to wait 1 millisecond before calling .dropdown('toggle'). Like this.
function OpenDropDown() {
$('.dropdown-menu').dropdown('toggle');
};
$('.collapse.navbar-collapse').on('show.bs.collapse', function () {
window.setTimeout(OpenDropDown, 1);
});
推荐答案
尝试这个:
$(function () {
$('.dropdown-menu').dropdown('toggle');
});
这篇关于Bootstrap 3使用Javascript打开页面加载下拉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!