CodeLab
Show Output
 
xxxxxxxxxx
35
 
1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
<meta charset="utf-8">
5
<title>Selecting Elements that Doesn't Match a Condition in jQuery</title>
6
<style>
7
    .highlight{
8
        background: yellow;
9
    }        
10
</style>
11
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
12
<script>
13
$(document).ready(function(){
14
    $("ul li").not(":even").addClass("highlight");
15
});
16
</script>
17
</head>
18
<body>
19
    <h2>Unordered List</h2>
20
    <ul>
21
        <li>First list item</li>
22
        <li>Second list item</li>
23
        <li>Third list item</li>
24
        <li>Fourth list item</li>
25
    </ul>
26
    <hr>
27
    <h2>Another Unordered List</h2>
28
    <ul>
29
        <li>First list item</li>
30
        <li>Second list item</li>
31
        <li>Third list item</li>
32
        <li>Fourth list item</li>
33
    </ul>
34
</body>
35
</html>
 

在微博、微信、公众号、小程序分享此示例。 如果您觉得有帮助,请给我们一个赞。