如何從當前標籤中刪除活動類並將活動類設置爲另一個點擊?我儘量做到這樣,但它不工作:)使用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) –