您的位置:首页 > 技术中心 > 前端框架 >

jquery中tr怎么删除id属性

时间:2022-04-02 16:15

在jquery中,可以利用removeAttr()方法删除tr元素的id属性,该方法的作用就是从被选元素中移除属性,将括号中的参数设置为“id”即可,语法为“需要删除id属性的tr元素对象.removeAttr("id");”。

本教程操作环境:windows10系统、jquery3.2.1版本、Dell G3电脑。

jquery中tr怎么删除id属性

removeAttr() 方法从被选元素中移除属性。

语法

  1. $(selector).removeAttr(attribute)

attribute 必需。规定从指定元素中移除的属性。

示例如下:

  1. <html>
  2. <head>
  3. <script type="text/javascript" src="/jquery/jquery.js"></script>
  4. <style>
  5. #city{
  6. background-color:pink;
  7. }
  8. </style>
  9. <script type="text/javascript">
  10. $(document).ready(function(){
  11. $("button").click(function(){
  12. $("tr").removeAttr("id");
  13. });
  14. });
  15. </script>
  16. </head>
  17. <body>
  18. <table border="1">
  19. <tr>
  20. <th>Month</th>
  21. <th>Savings</th>
  22. </tr>
  23. <tr>
  24. <td>January</td>
  25. <td>$100</td>
  26. </tr>
  27. <tr id="city">
  28. <td>January</td>
  29. <td>$100</td>
  30. </tr>
  31. <tr>
  32. <td>January</td>
  33. <td>$100</td>
  34. </tr>
  35. </table>
  36. <button>删除所有tr元素的id属性</button>
  37. </body>
  38. </html>

输出结果:

+8.gif

相关视频教程推荐:jQuery视频教程

以上就是jquery中tr怎么删除id属性的详细内容,更多请关注gxlsystem.com其它相关文章!

热门排行

今日推荐

热门手游