修改类的方法:1、使用removeClass()从tr元素中移除指定类,语法“$("tr").removeClass(class)”;2、使用addClass()给tr元素添加指定类,语法“$("tr").addClass(class)”。

本教程操作环境:windows7系统、jquery1.10.2版本、Dell G3电脑。
jquery修改tr类的方法
先使用removeClass()从tr元素中移除指定类
然后使用addClass()给tr元素添加指定类
示例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("button").click(function() {
$("tr").removeClass("intro1");
$("tr").addClass("intro2");
});
});
</script>
<style type="text/css">
.intro1
{
color:red;
}
.intro2
{
color:blue;
}
</style>
</head>
<body>
<table border="1">
<caption>人物信息</caption>
<tr class="intro1">
<th>姓名</th>
<th>年龄</th>
</tr>
<tr class="intro1">
<td>Peter</td>
<td>20</td>
</tr>
<tr class="intro1">
<td>Lois</td>
<td>20</td>
</tr>
</table><br />
<button>修改tr的类</button>
</body>
</html>
相关视频教程推荐:jQuery教程(视频)
以上就是jquery怎么修改tr的类的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号