简体   繁体   English

使用“标签”菜单面板,如何控制“活动”标签?

[英]Using panel for “tabs” menu, how can I control “active” tabs?

I created a bootstrap sidebar panel as the tab navigation. 我创建了一个引导侧边栏面板作为选项卡导航。 How can I control the tabs that are active? 如何控制活动的选项卡? I know there's the "active" class, but how do I actually set it so when you click a "tab" it will make it active so it highlights properly? 我知道有一个“活动”类,但是我实际上如何设置它,所以当您单击“选项卡”时它将使其活动,以便正确突出显示? Is this going to be a JS/Jquery thing? 这会成为JS / Jquery吗? I'm guessing this is a common thing, I just cannot find an answer via stackoverflow or google. 我猜这是很平常的事情,我只是无法通过stackoverflow或google找到答案。 Thank you! 谢谢!

If I understand what you are asking, you want to apply an active class when something is clicked. 如果我了解您的要求,则希望在单击某些内容时应用一个活动的班级。 You can do this with JQuery or JavaScript 您可以使用JQuery或JavaScript进行此操作

JQuery: jQuery的:

first of all, give all of the tabs or whatever a class, say 'foo'. 首先,给所有选项卡或任何类,说“ foo”。

THEN use this: 然后使用这个:

$('.foo').onClick(function(){
    $('.foo').removeClass('active');
    $(this).toggleClass('active');
});

this way, whenever an element with the class 'foo' is clicked, it adds the class 'active' to THAT ELEMENT ONLY, not to all the elements in the class. 这样,每当单击具有“ foo”类的元素时,就会将“ active”类仅添加到THAT ELEMENT中,而不是添加到该类中的所有元素上。 Click one element with class 'foo' and it removes the 'active' class from the previous element with 'active' class, and gives the class to the element that was just clicked only. 单击一个具有“ foo”类的元素,它会从上一个具有“ active”类的元素中删除“ active”类,并将该类提供给仅被单击的元素。

The above method makes it so that only one element with class 'foo' can have the 'active' class at a time. 上面的方法使得只有一个具有“ foo”类的元素可以同时具有“ active”类。 If you would rather have it so that multiple elements can have the 'active' class, remove the second line from my code sample. 如果您希望它具有多个元素可以具有“ active”类的功能,请从我的代码示例中删除第二行。

If I'm misunderstanding, comment and I'll see what I can do. 如果我有误会,请发表评论,然后我会做些什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM