Chinaunix首页 | 论坛 | 博客
  • 博客访问: 226216
  • 博文数量: 80
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 781
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-08 10:41
个人简介

爱莉清

文章分类

全部博文(80)

文章存档

2018年(1)

2017年(18)

2016年(49)

2015年(7)

2014年(5)

我的朋友

分类: jQuery

2016-05-24 16:34:51

简单的隐藏和显示的功能 的实现
实例:

点击(此处)折叠或打开

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>黄英文网页设计</title>
  6.     <script src="js/jquery-1.8.3.min.js"></script>
  7. </head>
  8. <body>
  9.     <p id="one">这里是将要显示或者是要隐藏的信息</p>
  10.     <button id="hide">隐藏</button>
  11.     <button id="show">显示</button>
  12.     <script>
  13.         $("#hide").click(function () {
  14.            $("#one").hide();
  15.         });
  16.         $("#show").click(function () {
  17.             $("#one").show();
  18.         });
  19.     </script>
  20. </body>
  21. </html>

语法:

$(selector).hide(speed,callback);

$(selector).show(speed,callback);

可选的 speed 参数规定隐藏/显示的速度,可以取以下值:"slow"、"fast" 或毫秒。

可选的 callback 参数是隐藏或显示完成后所执行的函数名称。

下面的例子演示了带有 speed 参数的 hide() 方法:

点击(此处)折叠或打开

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>黄英文网页设计</title>
  6.     <script src="js/jquery-1.8.3.min.js"></script>
  7. </head>
  8. <body>
  9.     <p id="one">这里是将要显示或者是要隐藏的信息</p>
  10.     <button id="hide">隐藏</button>
  11.     <button id="show">显示</button>
  12.     <button id="hide1000">隐藏1000ms</button>
  13.     <button id="show1000">显示1000ms</button>
  14.     <script>
  15.         $("#hide").click(function () {
  16.            $("#one").hide();
  17.         });
  18.         $("#show").click(function () {
  19.             $("#one").show();
  20.         });
  21.         $("#hide1000").click(function () {
  22.             $("#one").hide(1000);
  23.         });
  24.         $("#show1000").click(function () {
  25.             $("#one").show(1000);
  26.         });
  27.     </script>
  28. </body>
  29. </html>

jQuery toggle()

通过 jQuery,您可以使用 toggle() 方法来切换 hide() 和 show() 方法。

显示被隐藏的元素,并隐藏已显示的元素:


点击(此处)折叠或打开

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>黄英文网页设计</title>
  6.     <script src="js/jquery-1.8.3.min.js"></script>
  7. </head>
  8. <body>
  9.     <p id="one">这里是将要显示或者是要隐藏的信息</p>
  10.     <button id="hide">隐藏</button>
  11.     <button id="show">显示</button>
  12.     <button id="hide1000">隐藏1000ms</button>
  13.     <button id="show1000">显示1000ms</button>
  14.     <button id="showhide">显示或隐藏</button>
  15.     <script>
  16.         $("#hide").click(function () {
  17.            $("#one").hide();
  18.         });
  19.         $("#show").click(function () {
  20.             $("#one").show();
  21.         });
  22.         $("#hide1000").click(function () {
  23.             $("#one").hide(1000);
  24.         });
  25.         $("#show1000").click(function () {
  26.             $("#one").show(1000);
  27.         });
  28.         $("#showhide").click(function () {
  29.             $("#one").toggle(1000);
  30.         });
  31.     </script>
  32. </body>
  33. </html>





阅读(1010) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~