jQuery hide() 方法用于隐藏被选中的元素。用于元素的隐藏.

语法

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

参数

  • speed:可选参数。它指定隐藏元素的速度。它可能的值是slow、normal、fast和毫秒。
  • easing:可选参数指定用于过渡的缓动函数。linear表示匀速移动,swing表示在开头/结尾移动慢,在中间移动快
  • callback:可选参数。回调函数,其中回调函数是在隐藏完成之后执行。

例子

1)介绍jquery hide()的例子

<!DOCTYPE html>
<html>
<title>jQuery hide()方法-yxjc123.com</title>
<head>
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script>
$(document).ready(function(){
    $("#hide").click(function(){
        $("p").hide(500);
    });
	 $("#show").click(function(){
        $("p").show(500);
    });
});
</script>
</head>
<body>
<p>
<b>介绍jQuery hide()方法:</b><br/>
<br/>
点击下面的显示隐藏按钮看看效果
	
</p>
<button id="hide">隐藏</button>
<button id="show">显示</button>

</body>

</html>

效果:

jquery hide()方法

2) 有回调函数的例子:

 <!DOCTYPE html>
<html>
<title>jQuery hide()方法-yxjc123.com</title>
<head>
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script>
$(document).ready(function(){
    $("#hide").click(function(){
        $("p").hide(500,function(){
			//回调函数
			alert("hide函数完成");
		});
    });
	 $("#show").click(function(){
        $("p").show(500,function(){
			//回调函数
			alert("show函数完成");
		});
    });
});
</script>
</head>
<body>
<p>
<b>介绍jQuery hide()方法 :</b><br/>
<br/>
点击下面的显示隐藏按钮看看效果<br>
然后看下回调函数什么时候执行
</p>
<button id="hide">隐藏</button>
<button id="show">显示</button>

</body>

</html>