如何从当前标签中删除活动类并将活动类设置为另一个点击?我尽量做到这样,但它不工作:)使用jquery删除标签上的所有类,并添加新的
$(function() {
$(".bir").click(function() {
// remove classes from all
$("a").removeClass("active");
// add class to the one we clicked
$(".bir").addClass("active");
});
});
a {
color: #2a6496;
}
a.janduu {
color: #d11250;
}
<a href="form.php?lang=kr" data-toggle="tooltip" data-placement="bottom" title="кыргызча" class="janduu bir">КЫР</a>
<span>|</span>
<a href="form.php?lang=tr" data-toggle="tooltip" data-placement="bottom" title="türkçe" class="bir">TUR</a>
<span>|</span>
<a href="form.php?lang=en" data-toggle="tooltip" data-placement="bottom" title="english" class="bir">ENG</a>
<span>|</span>
<a href="form.php?lang=ru" data-toggle="tooltip" data-placement="bottom" title="русский" class="bir">РУС</a>
要删除使用'$(” a.active“)。removeClass(”active“);'并使用'$(this)'将它添加到clicked元素上。 '$(this).addClass('active');' – Tushar
看起来好像点击链接后,页面会刷新。页面刷新浏览器将重置动态添加的类“活动”。在这种情况下。后端语言将帮助你。 – Sachink
Tushar你建议使用双$(this) –