我是 jQuery 的初学者,我正在尝试修改脚本。脚本演示是 here 。现在,他们在所选选项卡上方添加了一行,这是我不想要的。我想做的只是向 anchor 添加一个类,例如
<a class="tab active" href="#">Tab Name</a>
这样我就可以使用 CSS 来更改事件按钮的背景颜色或其他颜色。
下面的代码是当您单击选项卡时当前的代码。
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');
}
}
关于javascript - jQuery 在选定选项卡上添加类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7436008/