修改类的方法: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的类的详细内容。