如何从链接切换 Bootstrap 下拉菜单? [英] How to toggle a Bootstrap dropdown menu from a link?

查看:25
本文介绍了如何从链接切换 Bootstrap 下拉菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行良好的 Bootstrap 下拉菜单.我还想做的是通过单击页面上其他地方的链接来触发菜单的打开.(这是有道理的,因为菜单项中的内容等.)文档页面说让链接执行类似 $('.dropdown-toggle').dropdown()$('.dropdown-toggle').dropdown() 的操作code>$('.dropdown-toggle').dropdown('toggle') 应该这样做,但两者都不适合我.有什么建议吗?

I have a Bootstrap dropdown menu that is working fine. What I'd like to do is also trigger the opening of the menu by clicking on a link elsewhere on the page. (This makes sense because of what's in the menu item, etc.) The doc page says that having the link do something like $('.dropdown-toggle').dropdown(), or maybe $('.dropdown-toggle').dropdown('toggle') should do this, but neither is working for me. Any suggestions?

推荐答案

try

$(".dropdown").addClass("open");

$(".dropdown").removeClass("open");

这篇关于如何从链接切换 Bootstrap 下拉菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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