首页  >  文章  >  web前端  >  jquery怎么移除td元素中的指定属性

jquery怎么移除td元素中的指定属性

青灯夜游
青灯夜游原创
2021-11-25 11:03:151522浏览

在jquery中,可以使用removeAttr()方法来移除td元素中的指定属性,该方法的作用就是从所有匹配的元素中移除指定的属性,具体语法为“$("td").removeAttr("需要移除的属性")”。

jquery怎么移除td元素中的指定属性

本教程操作环境:windows7系统、jquery1.10.2版本、Dell G3电脑。

在jquery中,可以使用removeAttr()方法来移除td元素中的指定属性。

removeAttr() 方法可以从所有匹配的元素中移除指定的属性。

语法:

$(selector).removeAttr(attribute)
  • attribute :规定从指定元素中移除的属性,不可省略。    

示例:移除td元素中的id属性

<!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() {
					$("td").removeAttr("id")
				});
			});
		</script>
		<style>
			#Peter{
				background-color: #FFC0CB;
			}
		</style>
	</head>
	<body>
		<table border="1">
			<caption>人物信息</caption>
			<tr>
				<th>姓名</th>
				<th>年龄</th>
			</tr>
			<tr>
				<td id="Peter">Peter</td>
				<td>20</td>
			</tr>
			<tr>
				<td>Lois</td>
				<td>20</td>
			</tr>
		</table><br />
		<button>移除td中的id属性</button>
	</body>
</html>

1.gif

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

以上是jquery怎么移除td元素中的指定属性的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn