jQuery中hide()方法用法实例

  本文实例讲述了jQuery中hide()方法用法。分享给大家供大家参考。具体分析如下:

  此方法可以将匹配元素隐藏。

  hide()方法的用法:

  此方法如果没有对隐藏效果加以时间限定,那么匹配元素会被瞬间隐藏。例如:

  

复制代码 代码如下:
$("div").hide()

  以上代码可以将所有div元素瞬间隐藏。

  如果方法对隐藏效果加以时间限定,那么匹配元素将会在限定的事件内以比较优雅的形式隐藏。例如:

  

复制代码 代码如下:
$("div").hide(2000)

  以上代码可以将所有div元素在2000毫秒(2秒)内隐藏。

  此方法也可以在隐藏完成后触发一个回调函数。例如:

  

复制代码 代码如下:
$("div").hide(2000,function(){alert("我隐藏好了")});

  实例代码:

  

复制代码 代码如下:

  <!DOCTYPE html>

  <html>

  <head>

  <meta charset=" utf-8">

  <meta name="author" content="http://www.glzy8.com/" />

  <title>hide()函数-管理资源吧</title>

  <style type="text/css">

  div{

  color:blue;

  background-color:green;

  width:100px;

  height:100px;

  margin-top:10px;

  }

  </style>

  <script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>

  <script type="text/javascript">

  $(document).ready(function(){

  $("#first").click(function(){

  $(".first").hide();

  })

  $("#second").click(function(){

  $(".second").hide(2000,function(){alert("我隐藏好了")});

  })

  })

  </script>

  </head>

  <body>

  <div class="first"></div>

  <div class="second"></div>

  <button id="first">瞬间隐藏</button>

  <button id="second">优雅的隐藏</button>

  </body>

  </html>

  以上代码能够在隐藏完成以后触发回调函数,于是弹出一个提示框。

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