html代码:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript" src="jquery-3.1.0.js"></script>
<script type="text/javascript" src="JavaScript.js"></script>
</head>
<body>
<p>我是段落</p>
<button id="btn1">隐藏</button>
<button id="btn2">显示</button>
<button id="btn3">切换</button>
</body>
</html>
JQuery代码:
$(document).ready(function () {
$("#btn1").click(function () {
$("p").hide("slow"); // 设置隐藏的速度;
});
$("#btn2").click(function () {
$("p").show(3000, showColor); // 参数1:设置显示的速度;参数2:显示完成后要执行的函数;
$("p").css("background-color", "green"); // 该设置会在刚开始显示的时候就执行;
});
$("#btn3").click(function () {
$("p").toggle(1000); // 切换隐藏和显示;
});
});
function showColor() {
$("p").css("background-color", "blue");
}