twitter-bootstrap 使用 Bootstrap 处理下拉项选择事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18821303/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 18:24:37  来源:igfitidea点击:

handling dropdown item selected event using Bootstrap

twitter-bootstrap

提问by user2782692

Hi I have just started using twitter bootstrap and trying my hand on handling dropdown events.

嗨,我刚刚开始使用 twitter bootstrap 并尝试处理下拉事件。

I want to handle the dropdown item selected event, that is, when the user clicks on a particular item, a table should be displayed just below the dropdown. Can anyone please help me out in achieving this? Thank you.

我想处理下拉项选择事件,即当用户单击特定项时,应在下拉列表正下方显示一个表格。任何人都可以帮助我实现这一目标吗?谢谢你。

<ul class="dropdown-menu">
    <!-- dropdown menu links -->
    <li><a href="#" id="action-1">How are you?</a></li>
    <li><a href="#2">What is your name</a></li>
    <li><a href="#section-2">Section 2</a></li>
</ul>

回答by koala_dev

There's no such event in Bootstrap, the only events you can handle for dropdowns are show, shown, hide, hidden, you can use simple jQuery for this though:

Bootstrap 中没有这样的事件,您可以为下拉列表处理的唯一事件是show, shown, hide, hidden,您可以为此使用简单的 jQuery:

$('.dropdown-menu a').click(function(){
    //Show table
});

回答by guymac

You can handle the function in the menu itself, e.g.

您可以在菜单本身中处理该功能,例如

<li><a href="javascript:itemSelected('A')">A. Hello World!</a></li>