<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script src="../../jquery-2.1.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$("div:odd").addClass("demo");//偶数div添加demo样式
$("div:even").removeClass("demo");//奇数div移除demo样式
$("div:eq(2)").addClass("demo");//给指定标号的div添加demo样式 注意:标号是从0开始的
})
</script>
<style type="text/css">
.demo{
font-style:inherit;
color:#00F;}
</style>
</head>
<body>
<div id="strdiv1">
JQuery攻略学习!!!
</div>
<div id="strdiv2">
JQuery攻略学习!!
</div>
<div id="strdiv3">
JQuery攻略学习!!
</div>
</body>
</html>
操作偶数、奇数、指定下标的元素
最新推荐文章于 2022-05-06 06:50:15 发布