jQuery 在选定选项卡上添加类 [英] jQuery Adding Class on Selected Tab
本文介绍了jQuery 在选定选项卡上添加类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 jQuery 的初学者,我正在尝试修改脚本.脚本演示位于此处.现在,他们在所选选项卡上方添加了一行,这是我不想要的.我想要做的只是像
I am a beginner with jQuery and I am trying to modify a script. The script demo is here. Right now, they add a line above the selected tab, which I don't want. What I want to do is just add a class to the anchor like a
<a class="tab active" href="#">Tab Name</a>
这样我就可以使用 CSS 来更改活动按钮的背景颜色或其他内容.
that way I can just use CSS to change the background color or something for the active buttons.
下面的代码是当你点击一个标签时他们当前拥有的代码.
The code below is what they currently have for when you click on a tab.
the_tabs.click(function(e){
/* "this" points to the clicked tab hyperlink: */
var element = $(this);
/* If it is currently active, return false and exit: */
if(element.hasClass('.active')) return false;
$(this).addClass('active')
推荐答案
the_tabs.click(function(e){
var element = $(this);
if( element.hasClass('active') ) {
return false;
}
else {
the_tabs.removeClass('active');
element.addClass('active');
}
}
这篇关于jQuery 在选定选项卡上添加类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文