<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>温故而知新</title>
<style></style>
</head>
<body>
<div class="test">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</div>
</body>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<!-- <script src="./myjQuery.js"></script> -->
<script>
/*
方法A和方法B的效果都是一样的,
只是方法B操作性大一点。
*/
//方法A(filter(":even")偶数全部留下)
$(".test ul li")
.filter(":even")
.css({ color: '#ff0000' })
//方法B
$(".test ul li")
.filter(function (index, ele) {
return index % 2 == 0
})
.css({ color: '#ff0000' })
/*
现在你如果看懂了jQ的filter方法,
那么not方法也就懂了,因为filter与not方法
是相反的。
*/
$(".test ul li")
.not(":even")
.css({ color: '#0000ff' })
</script>
</html>