天天看点

隐藏显示控制(is/hide/show)

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8" />

<title></title>

<style>

*

{

margin: 0px;

padding: 0px;

}

#btn

{

width: 500px;

height:500px;

margin: 100px 0px 0px 100px;

}

.p

{

border: 5px greenyellow solid;

margin: 0px 0px 0px 100px;

width: 500px;

display: none;

}

</style>

<script type="text/javascript" src="jquery-1.7.2.js"></script>

<script type="text/javascript">

$(function(){

$("#btn").click(function(){

//使用 is() 方法, 来判断某个给定的 jQuery 对象是否符合指定

var flag = $(".p").is(":hidden");

if(flag)

{

$(".p").show();

}

else

{

$(".p").hide();

}

})

})

</script>

</head>

<body>

<input type="button" value="点我有惊喜" id="btn"/>

<p class="p">惊喜惊喜惊喜惊喜惊喜惊喜惊喜惊喜惊喜惊喜惊喜惊喜惊喜惊喜惊喜

惊喜惊喜惊喜惊喜惊喜惊喜惊喜惊喜惊喜惊喜惊喜惊喜惊喜

惊喜惊喜惊喜惊喜惊喜惊喜惊喜惊喜惊喜惊喜惊喜惊喜惊喜</p>

</body>

</html>

继续阅读