jQuery鼠标移入移出事件切换 jQuery实现鼠标移入移出事件切换功能示例

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

jQuery鼠标移入移出事件切换 jQuery实现鼠标移入移出事件切换功能示例

shuair   2021-03-30 我要评论

本文实例讲述了jQuery实现鼠标移入移出事件切换功能。分享给大家供大家参考,具体如下:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <script src="http://libs.baidu.com/jquery/1.8.0/jquery.min.js"></script>
    <style>
    #msg {
      color: #3c763d;
      background-color: #dff0d8;
      border-color: #d6e9c6;
      border-radius: 4px;
      padding: 15px;
    }
    </style>
    <title></title>
    <script>
      $(function(){
        $(msg).on({
          mouseover : function(){
            $(this).wrap("<h1>") ;
          } ,
          mouseout : function(){
            $(this).unwrap() ;
          } 
        }) ;
      }) ; 
    </script>
  </head>
  <body> 
    <p id="msg">Hello World !!!</p>
  </body>
</html>

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

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

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

注:关于javascript事件说明可参考本站javascript事件与功能说明大全http://tools.softyun.net/table/javascript_event

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <script src="http://libs.baidu.com/jquery/1.7.0/jquery.min.js"></script>
    <style>
    #msg {
      color: #3c763d;
      background-color: #dff0d8;
      border-color: #d6e9c6;
      border-radius: 4px;
      padding: 15px;
    }
    </style>
    <title></title>
    <script>
      $(function(){
        $(msg).hover(
          function(){
            $(this).wrap("<h1>") ;
          } ,
          function(){
            $(this).unwrap() ;
          } 
        ) ;
      }) ; 
    </script>
  </head>
  <body> 
    <p id="msg">Hello World !!!</p>
  </body>
</html>

代码运行效果:

希望本文所述对大家jQuery程序设计有所帮助。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们