How to toggle a Bootstrap dropdown menu from a lin

2019-02-24 08:54发布

问题:

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?

回答1:

try

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

and

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