jQuery 抄袭笔记(27) :导航3
26 Oct 2011js里面void是一个操作符,该操作符计算表达式的值,但是不返回任何内容。
<a href="javascript:void(0);">这里用到void(0)表示取消A链接,相当于<a href="#">,
但是也是有区别:void(0)什么都不做,href="#"会回到顶部。
01 <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
02 <html xmlns=“http://www.w3.org/1999/xhtml”>
03 </span>
04 <meta http-equiv=“Content-Type” content=“text/html; charset=gb2312″ />
05</span>Hello Lazynight~</title>
06 <script type=“text/javascript” src=“jquery-1.1.3.pack.js”></script>
07 <script language=“JavaScript” type=“text/javascript”>
08 $(document).ready(function(){
09 var li=$(“#menuNav >li”);//找到#menuNav中子元素li
10 var ul;
11 li.each(function(i){
12 li.eq(i).hover(function(){
13 $(this).find(“ul”).show();// 找到li里面的ul元素设置为显示
14 },
15 function(){
16 $(this).find(“ul”).hide();
17 })
18 });
19 });
20 </script>
21
22 * {margin:0px; padding:0px;list-style:none;}
23 body {font-size:16px;}
24 .nav {float:left;clear:both;margin:100px;display:inline;}
25 .nav li {float:left;position:relative;}
26 .nav li a {display:block;width:100px;padding:2px; text-align:center;color:#fff;background-color:#000;}
27 .nav li a:hover {background-color:#000;color:#fff;}
28 .nav li ul {position:absolute;display:none;border:1px solid;}
29 .nav li ul li {float:none;}
30 .nav li ul li a {background-color:#fff;color:#000;}
31
32 </head>
33 </span>
34 <ul id=“menuNav” class=“nav”>
35<a</span> href=“javascript:void(0);”>首页</a></li>
36<a</span> href=“javascript:void(0);”>会员</a>
37
02 <html xmlns=“http://www.w3.org/1999/xhtml”>
03 </span>
04 <meta http-equiv=“Content-Type” content=“text/html; charset=gb2312″ />
05
06 <script type=“text/javascript” src=“jquery-1.1.3.pack.js”></script>
07 <script language=“JavaScript” type=“text/javascript”>
08 $(document).ready(function(){
09 var li=$(“#menuNav >li”);//找到#menuNav中子元素li
10 var ul;
11 li.each(function(i){
12 li.eq(i).hover(function(){
13 $(this).find(“ul”).show();// 找到li里面的ul元素设置为显示
14 },
15 function(){
16 $(this).find(“ul”).hide();
17 })
18 });
19 });
20 </script>
21
22 * {margin:0px; padding:0px;list-style:none;}
23 body {font-size:16px;}
24 .nav {float:left;clear:both;margin:100px;display:inline;}
25 .nav li {float:left;position:relative;}
26 .nav li a {display:block;width:100px;padding:2px; text-align:center;color:#fff;background-color:#000;}
27 .nav li a:hover {background-color:#000;color:#fff;}
28 .nav li ul {position:absolute;display:none;border:1px solid;}
29 .nav li ul li {float:none;}
30 .nav li ul li a {background-color:#fff;color:#000;}
31
32 </head>
33 </span>
34 <ul id=“menuNav” class=“nav”>
35
36
37
- </span>
- <a</span> href=“javascript:void(0);” onclick=“javascript:alert($(this).html());”>Tomi_Enn</a></li>
39- <a</span> href=“javascript:void(0);” onclick=“javascript:alert($(this).html());”>暗白</a></li>
40- <a</span> href=“javascript:void(0);” onclick=“javascript:alert($(this).html());”>Maizi</a></li>
41 </ul>
42 </li>
43- <a</span> href=“javascript:void(0);”>音乐</a>
44- </span>
- <a</span> href=“javascript:void(0);” onclick=“javascript:alert($(this).html());”>摇滚</a></li>
46- <a</span> href=“javascript:void(0);” onclick=“javascript:alert($(this).html());”>轻音乐</a></li>
47- <a</span> href=“javascript:void(0);” onclick=“javascript:alert($(this).html());”>新世纪</a></li>
48 </ul>
49 </li>
50- <a</span> href=“javascript:void(0);”>小组</a>
51- </span>
- <a</span> href=“javascript:void(0);” onclick=“javascript:alert($(this).html());”>电影原声</a></li>
53- <a</span> href=“javascript:void(0);” onclick=“javascript:alert($(this).html());”>收容所</a></li>
54- <a</span> href=“javascript:void(0);” onclick=“javascript:alert($(this).html());”>夜阑</a></li>
55 </ul>
56 </li>
57 </ul>
58 </body>
59 </html> </div> 下载源码 转载请注明:[于哲的博客][1] » [jQuery 抄袭笔记(27) :导航3][2] [1]: http://lazynight.me [2]: http://lazynight.me/692.html - <a</span> href=“javascript:void(0);” onclick=“javascript:alert($(this).html());”>收容所</a></li>
52 - <a</span> href=“javascript:void(0);” onclick=“javascript:alert($(this).html());”>轻音乐</a></li>
45 - <a</span> href=“javascript:void(0);” onclick=“javascript:alert($(this).html());”>暗白</a></li>
38