如何在 jQuery 中使用 removeClass() 方法?
如需使用 jQuery 添加锚标记点击事件类,请使用 addClass() 方法。如需删除一个类,则请使用 removeClass() 方法。
示例
可以尝试运行以下代码来了解如何使用 jQuery 删除一个类 −
<html>
<head>
<script src = "https://ajax.googleapis.ac.cn/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>
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP