<html>
<head>
<script src="script/jquery-1.1.3.1.js" type="text/javascript">
</script>
<script type="text/javascript">
$(function(){
$("button").click(function(){
alert('the class attribute of the second p is '+$("body p:eq(1)").attr("class"));
$("body p:eq(0)").removeAttr("class");
});
});
</script>
</head><body>
<h1 class="0">title</h1>
<p class="1">paragraph</p>
<p class="2">the other paragraph</p>
<button>delete the class of p</button>
</body></html>
显示the class attribute of the second p is 2,而且第一个p标签的class也被擦除了。
代码练习:测试dom元素的属性
最新推荐文章于 2024-02-29 19:35:37 发布
