本文实例讲述了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="https://www.jb51.net/" />
<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="/UploadFiles/2021-04-02/jquery-1.8.3.js"> <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程序设计有所帮助。

标签:
jQuery,hide(),方法,用法

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
评论“jQuery中hide()方法用法实例”
暂无“jQuery中hide()方法用法实例”评论...