jquery中tr怎么删除id属性

jquery中tr怎么删除id属性,第1张

jquery中tr怎么删除id属性

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

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

jquery中tr怎么删除id属性

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

语法

$(selector).removeAttr(attribute)

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

示例如下:

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<style>
#city{
background-color:pink;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $("tr").removeAttr("id");
  });
});
</script>
</head>
<body>
<table border="1">
  <tr>
    <th>Month</th>
    <th>Savings</th>
  </tr>
  <tr>
    <td>January</td>
    <td>0</td>
  </tr>
  <tr id="city">
    <td>January</td>
    <td>0</td>
  </tr>
  <tr>
    <td>January</td>
    <td>0</td>
  </tr>
</table>
<button>删除所有tr元素的id属性</button>
</body>
</html>

输出结果:

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

以上就是jquery中tr怎么删除id属性的详细内容,

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/697864.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-04-22
下一篇2022-04-22

发表评论

登录后才能评论

评论列表(0条)

    保存