案例:jQuery案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<html>
2
<head>
3
<script type="text/javascript" src="/js/jquery.js"></script>
4
<script type="text/javascript">
5
$(document).ready(function(){
6
  $("button").click(function(){
7
    $('p').addClass(function(n){
8
      return 'par_' + n;
9
    });
10
  });
11
});
12
</script>
13
<style type="text/css">
14
.par_0
15
{
16
color:blue;
17
}
18
.par_1
19
{
20
color:red;
21
}
22
</style>
23
</head>
24
25
<body>
26
<h1>This is a heading</h1>
27
<p>This is a paragraph.</p>
28
<p>This is another paragraph.</p>
29
<button>向 p 元素添加类</button>
30
</body>
31
</html>
32