Bootstrap 3使用Javascript打开页面加载下拉 [英] Bootstrap 3 Open Drop Down on page load with Javascript

查看:214
本文介绍了Bootstrap 3使用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.

http: //jsfiddle.net/G4k4F/3

编辑:当显示导航栏时,使用定时器等待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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆