锋利的Jquery,点击显示隐藏div

点击显示隐藏div

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html>
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5 <title>1-5-1</title>
 6 <style type="text/css">
 7 #menu { 
 8     width:300px; 
 9 }
10 .has_children{
11     background : #555;
12     color :#fff;
13     cursor:pointer;
14 }
15 .highlight{
16     color : #fff;
17     background : green;
18 }
19 div{
20     padding:0;
21 }
22 div a{
23     background : #888;
24     display : none;
25     float:left;
26     width:300px;
27 }
28 </style>
29 <!-- 引入 jQuery -->
30 <script src="../../scripts/jquery-1.3.1.js" type="text/javascript"></script>
31 <script type="text/javascript">
32 //等待dom元素加载完毕.
33 $(document).ready(function(){
34     $(".has_children").click(function(){
35         $(this).addClass("highlight").children("a").show().end().siblings().removeClass("highlight").children("a").hide();
36     });
37 });
38 </script>
39 </head>
40 <body>
41 <div >
42     <div class="has_children">
43         <span>第1章-认识jQuery</span>
44         <a>1.1-JavaScript和JavaScript库</a>
45         <a>1.2-加入jQuery</a>
46         <a>1.3-编写简单jQuery代码</a>
47         <a>1.4-jQuery对象和DOM对象</a>
48         <a>1.5-解决jQuery和其它库的冲突</a>
49         <a>1.6-jQuery开发工具和插件</a>
50         <a>1.7-小结</a>
51     </div>
52     <div class="has_children">
53         <span>第2章-jQuery选择器</span>
54         <a>2.1-jQuery选择器是什么</a>
55         <a>2.2-jQuery选择器的优势</a>
56         <a>2.3-jQuery选择器</a>
57         <a>2.4-应用jQuery改写示例</a>
58         <a>2.5-选择器中的一些注意事项</a>
59         <a>2.6-案例研究——类似淘宝网品牌列表的效果</a>
60         <a>2.7-还有其它选择器么?</a>
61         <a>2.8-小结</a>
62     </div>
63     <div class="has_children">
64         <span>第3章-jQuery中的DOM操作</span>
65         <a>3.1-DOM操作的分类</a>
66         <a>3.2-jQuery中的DOM操作</a>
67         <a>3.3-案例研究——某网站超链接和图片提示效果</a>
68         <a>3.4-小结</a>
69     </div>
70 </div>
71 </body>
72 </html>