jQuery show()和hide()是最常用的效果。
- show()–显示匹配的元素。
- hide()–隐藏匹配的元素。
两种方法都将支持持续时间作为参数:慢速,快速或精确毫秒。 如果省略此参数,则默认为400毫秒。
自己尝试
<html>
<head>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<style type="text/css">
p{
padding:8px;
margin:16px;
border:1px solid blue;
width:250px;
height:50px;
background-color:#999999;
color:white;
}
</style>
</head>
<body>
<h1>jQuery show() and hide() example</h1>
<p>Hello, this show() and hide() example</p>
<button id=show>show()</button>
<button id=hide>hide()</button>
<button id=reset>Reset</button>
<script type="text/javascript">
$("#show").click(function () {
$("p").show('fast');
});
$("#hide").click(function () {
$("p").hide(1000);
});
$("#reset").click(function(){
location.reload();
});
</script>
</body>
</html>
翻译自: https://mkyong.com/jquery/jquery-show-and-hide-example/