如何在 jQuery 中使用 removeClass() 方法?
若要使用 jQuery 在點選錨點標籤時為其新增一個類,請使用 addClass() 方法。若要刪除一個類,請使用 removeClass() 方法。
示例
你可以嘗試執行以下程式碼來學習如何使用 jQuery 去掉一個類 −
<html>
<head>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("a").click(function(){
$("a.active").removeClass("active");
$(this).addClass("active");
});
});
</script>
<style>
.active {
font-size: 22px;
}
</style>
</head>
<body>
<a href="#" class="demo1">One</a>
<a href="#" class="demo2">Two</a>
<p>Click any of the link above and you can see the changes.</p>
</body>
</html>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP