JQuery鼠标 点击显示 隐藏 和 鼠标移入 显示 移出隐藏 效果

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  2. <html>  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  5. <title>jQuery事件-div的显示隐藏及鼠标的移入移出</title>  
  6. <style>  
  7. .header{  
  8.     width:302px;  
  9.     height:40px;  
  10.     background:green;  
  11.     font-size:20px;  
  12.     margin-bottom: 0px;  
  13. }  
  14. .content{  
  15.     width:300px;  
  16.     border:1px solid #333;  
  17.     background:#CCC;  
  18.     display: none;  
  19.     margin-top:0px;  
  20. }  
  21. </style>  
  22. </head>  
  23. <script type="text/javascript" src="jquery-1.11.1.js"></script>  
  24. <script type="text/javascript">  
  25.     $(function (){  
  26.         //显示隐藏  
  27.         $(".header").click(function (){  
  28.             var flag = $(".content").is(":hidden");  
  29.             if(flag){  
  30.                 $(".content").show();  
  31.             }else{  
  32.                 $(".content").hide();  
  33.             }  
  34.         });  
  35.           
  36.         /*  
  37.         //使用bind的绑定事件,跟上上面的效果是一样的  
  38.         $(".header").bind("click", function (){  
  39.             var flag = $(".content").is(":hidden");  
  40.             if(flag){  
  41.                 $(".content").show();  
  42.             }else{  
  43.                 $(".content").hide();  
  44.             }  
  45.         });  
  46.         */  
  47.         /*  
  48.         //鼠标的移入移出  
  49.         $(".header").mouseover(function (){  
  50.             $(".content").show();  
  51.         }).mouseout(function (){  
  52.             $(".content").hide();  
  53.         });  
  54.         */  
  55.         /*  
  56.         //合成事件 hover()  
  57.         $(".header").hover(function (){  
  58.             $(".content").show();  
  59.         },function (){  
  60.             $(".content").hide();  
  61.         });  
  62.         */  
  63.           
  64.     });  
  65. </script>  
  66. <body>  
  67.     <h5 class="header" align="center">什么是jQuery?</h5>  
  68.     <div class="content">  
  69.         Jquery是继prototype之后又一个优秀的Javascript库。它是轻量级的js库 ,  
  70.         它兼容CSS3,还兼容各种浏览器(IE 6.0+, FF 1.5+, Safari 2.0+, Opera 9.0+),  
  71.         jQuery2.0及后续版本将不再支持IE6/7/8浏览器。  
  72.         jQuery使用户能更方便地处理HTML(标准通用标记语言下的一个应用)、events、实现动画效果,  
  73.         并且方便地为网站提供AJAX交互。jQuery还有一个比较大的优势是,它的文档说明很全,  
  74.         而且各种应用也说得很详细,同时还有许多成熟的插件可供选择。  
  75.         jQuery能够使用户的html页面保持代码和html内容分离,也就是说,  
  76.         不用再在html里面插入一堆js来调用命令了,只需要定义id即可。  
  77.     </div>  
  78. </body>  
  79. </html>  

猜你喜欢

转载自blog.csdn.net/weixin_41883384/article/details/80266749