我从另一个问题中抓取了这个片段:
<script type='text/javascript' >
$(document).ready(function () {
$("div.content ul li a")
.mouseover(function () {
var t = $(this);
if (!t.hasClass("clicked")) { // very easy to check if element has a set of styles
t.addClass('mouseover');
}
})
.mouseout(function () { // attach event here instead of inside mouse over
$(this).removeClass('mouseover');
});
$("div.content ul li a").click(function () {
var t = $(this);
t.toggleClass("clicked");
if (t.hasClass("clicked")) {
t.removeClass('mouseover');
} else {
t.addClass('mouseover');
}
});
});
</script>
我想要的最后一件事是在单击另一个选项卡时恢复选项卡的正常 css。例如,当我单击 tab1 时,选项卡的 bgcolors 为白色,当我进入 Tab2 时,它变为黑色。.Tab1 变为白色,Tab2 变为黑色
<ul>
<li>
<a href="#Tab1">Tab 1</a>
</li>
<li>
<a href="#Tab2">Tab 2</a>
</li>
</ul>
假设这是 CSS 部分
ul li a {background-color: white;}
ul li a.mouseover {background-color: black;}
ul li a.mouseout {background-olor: white;}
ul li a.clicked {background-color: black;}