<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery 显示与隐藏</title>
<script type="text/javascript" src="js/jquery-1.10.1.js"></script>
<script type="text/javascript" src="js/demo.js"></script>
<link rel="stylesheet" type="text/css" href="css/demo.css" />
</head>
<body>
<input class="show" type="button" value="显示" />
<input class="hide" type="button" value="隐藏" />
<div id="box">
</div>
</body>
</html>
/* CSS Document */
#box{ width:200px; height:160px; background:#0F9;}
$(function(){
/*
$('.show').click(function(){//显示
$('#box').show();
});
$('.hide').click(function(){//隐藏
$('#box').hide();
});
$('.show').click(function(){
$('#box').show(1000);//显示用了 1 秒
});
$('.hide').click(function(){
$('#box').hide(1000);//隐藏用了 1 秒
});
*/
//除了直接使用毫秒来控制速度外,jQuery 还提供了三种预设速度参数字符串:show、normal和fast,
//分别对应 600 毫秒、400 毫秒和 200 毫秒
$('.show').click(function(){
$('#box').show('fast');//200毫秒
});
$('.hide').click(function(){
$('#box').hide('');//默认 400 毫秒
});
});
效果图: