jQuery练习1--给网页中所有的 <p> 元素添加 onclick 事件

 1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 2 <html>
 3   <head>
 4     <title>exe_1.html</title>
 5     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
 6     <script type="text/javascript" src="../js/jquery-1.6.js"></script>
 7   </head>
 8   <body>
 9       <p>段落1</p>
10       <p>段落2</p>
11       <p>段落3</p>
12       <script type="text/javascript">
13       
14           //定位所有<p>元素
15           
16           //$("p").each(function(){
17           //    alert($(this).html());
18           //});
19           
20           //$("p").each(function(){
21           //    $(this).click(function(){
22           //        alert($(this).html());
23           //    });
24           //});
25           
26           $("p").each(function(){
27               $(this).dblclick(function(){
28                   alert($(this).html());
29               });
30           });
31           
32       </script>
33   </body>
34 </html>

 

posted @ 2013-05-09 20:01  hacket520  阅读(2057)  评论(0编辑  收藏  举报