Html Bootstrap 3 的活动按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18391272/
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
Active Buttons with Bootstrap 3
提问by megashigger
In my navbar, I want my buttons to become active (shaded) when I click on them. Right now, I can only permanently make them active or non-active but don't know how to have it change once I click on them. I'm using the new Bootstrap (3.0).
在我的导航栏中,当我点击它们时,我希望我的按钮变得活跃(阴影)。现在,我只能永久地使它们处于活动状态或非活动状态,但是一旦我点击它们,我就不知道如何改变它。我正在使用新的 Bootstrap (3.0)。
For example:
例如:
Non-Active
不活跃
<li><%= link_to "Contact", contact_path %></li>
Active
积极的
<li class="active"><%= link_to "About", about_path %></li>
I want it to be active/non-active depending on whether the current page is selected or not.
我希望它根据是否选择当前页面而处于活动/非活动状态。
回答by Eric Hotinger
Use JavaScript.
使用 JavaScript。
Example with jQuery:
jQuery 示例:
$('ul li').click( function() {
$(this).addClass('active').siblings().removeClass('active');
});
Or with more bootstrap:
或者使用更多引导程序:
回答by kristenmills
Have you loooked at the simple-navigation gem?
你看过简单的导航宝石吗?
https://github.com/andi/simple-navigation
https://github.com/andi/simple-navigation
It has this functionality built in.
它内置了此功能。
回答by rawand
if you are using bootstrap you can write data-toggle="dropdown" for example Home
如果您使用的是引导程序,您可以编写 data-toggle="dropdown" 例如 Home