案例:jQuery案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
  <script type="text/javascript" src="/js/jquery.js"></script>
5
</head>
6
7
<body>
8
<ul>
9
  <li><strong>list</strong> item 1 - one strong tag</li>
10
  <li><strong>list</strong> item <strong>2</strong> -
11
    two <span>strong tags</span></li>
12
  <li>list item 3</li>
13
  <li>list item 4</li>
14
  <li>list item 5</li>
15
</ul>
16
17
<script>
18
$("li").click(function() {
19
  var $li = $(this),
20
    isWithTwo = $li.is(function() {
21
      return $('strong', this).length === 2;
22
    });
23
  if ( isWithTwo ) {
24
    $li.css("background-color", "green");
25
  } else {
26
    $li.css("background-color", "red");
27
  }
28
});
29
</script>
30
31
</body>
32
</html>
33