JQuery執行個體入門(添加滑鼠事件)

來源:互聯網
上載者:User
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" >
  3. <head>
  4.     <title>無標題頁</title>
  5.     <script type="text/javascript" src="js/jquery-1[1].2.6.min.js"></script>
  6.     
  7.     <style type="text/css"> 
  8.         .over {   
  9.             background:Red;  /*這個將是滑鼠高亮行的背景色*/  
  10.         }     
  11.         .color{
  12.             background:Green;
  13.         } 
  14.     </style> 
  15.     
  16.     <script type="text/javascript">     
  17.             $(document).ready(function() {   
  18.             $("#user").mouseover(function(){   
  19.                 $(this).removeClass("color").addClass("over");
  20.                 $(this).attr("height","100px");
  21.             })   
  22.             .mouseout(function(){   
  23.                 $(this).removeClass("over").addClass("color");
  24.             });   
  25.             })
  26.         </script>
  27. </head>
  28. <body>
  29.       <div id="user" class="color">滑鼠移動過來</div>
  30. </body>
  31. </html>

 http://wiki.jquery.org.cn/doku.php

 

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" >
  3. <head>
  4.     <title>無標題頁</title>
  5.     <script type="text/javascript" src="js/jquery-1[1].2.6.min.js"></script>
  6.     
  7.     <style type="text/css"> 
  8.         .over {   
  9.             background:Red;  /*這個將是滑鼠高亮行的背景色*/  
  10.         }     
  11.         .color{
  12.             background:Green;
  13.         } 
  14.     </style> 
  15.     
  16.     <script type="text/javascript">     
  17.         /*    
  18.            此教程目的是讓那些新手通過實際應用,對jquery有一個初步瞭解。   
  19.            傳說中的ready   
  20.            $(document).ready() 作用就是 在頁面載入完成之後執行 封裝在裡面的js.   
  21.            你可以在一個頁面中使用任意多個$(document).ready事件   
  22.         */  
  23.           /*----------------傳說中的ready-------------------*/  
  24.             $(document).ready(function() {   
  25.         /*------------------end-----------------*/  
  26.   
  27.          /*jQuery的鏈式操作   
  28.           正常情況下應該寫成   
  29.                 $("#user").mouseover(function(){   
  30.                 $(this).addClass("over");   
  31.             });   
  32.             $("#user").mouseout(function(){   
  33.                 $(this).removeClass("over");     
  34.             });   
  35.           
  36.             但是我們現在寫成 $("#user").mouseover().mouseout()這種形式;   
  37.          因為 在jQuery中,執行完mouseover或者mouseout等方法之後,都會返回當前的對象,所以可以進行鏈式操作   
  38.          */  
  39.            /*----------------鏈式操作例子-------------------*/  
  40.             $("#user").mouseover(function(){   
  41.                 $(this).removeClass("color").addClass("over");
  42.                 $(this).attr("height","100px");
  43.             })   
  44.             .mouseout(function(){   
  45.                 $(this).removeClass("over").addClass("color");
  46.             });   
  47.               /*-----------------end-----------------*/  
  48.             })
  49.         </script>
  50. </head>
  51. <body>
  52.       <div id="user" class="color">滑鼠移動過來</div>
  53. </body>
  54. </html>

去掉注釋,清晰一些

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.