分享

jQuery 鼠标移入移出事件切换

 昨夜雾浓 2018-04-24
  1. <!DOCTYPE html>  
  2. <html>  
  3.     <head>  
  4.         <meta charset="utf-8" />  
  5.         <script type="text/javascript" src="js/jquery-3.1.1.min.js" ></script>  
  6.         <link rel="stylesheet" href="css/style.css" />  
  7.         <title></title>  
  8.         <script>  
  9.             $(function(){  
  10.                 $(msg).on({  
  11.                     mouseover : function(){  
  12.                         $(this).wrap("<h1>") ;  
  13.                     } ,  
  14.                     mouseout : function(){  
  15.                         $(this).unwrap() ;  
  16.                     }   
  17.                 }) ;  
  18.             }) ;    
  19.         </script>  
  20.     </head>  
  21.     <body>   
  22.         <p id="msg">Hello World !!!</p>  
  23.     </body>  
  24. </html>  

hover() 方法规定当鼠标指针悬停在被选元素上时要运行的两个函数。

jQuery 1.7 版本前该方法触发 mouseenter mouseleave 事件。

jQuery 1.8 版本后该方法触发 mouseover mouseout 事件。

  1. <!DOCTYPE html>  
  2. <html>  
  3.     <head>  
  4.         <meta charset="utf-8" />  
  5.         <script type="text/javascript" src="js/jquery-3.1.1.min.js" ></script>  
  6.         <link rel="stylesheet" href="css/style.css" />  
  7.         <title></title>  
  8.         <script>  
  9.             $(function(){  
  10.                 $(msg).hover(  
  11.                     function(){  
  12.                         $(this).wrap("<h1>") ;  
  13.                     } ,  
  14.                     function(){  
  15.                         $(this).unwrap() ;  
  16.                     }   
  17.                 ) ;  
  18.             }) ;    
  19.         </script>  
  20.     </head>  
  21.     <body>   
  22.         <p id="msg">Hello World !!!</p>  
  23.     </body>  
  24. </html>  


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约