jQuery hide()
<!DOCTYPE html> |
<html> |
<head> |
<meta charset="utf-8"> |
<title>芝麻教程(web3.xin)</title> |
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"> |
</script> |
<script> |
$(document).ready(function(){ |
$("p").click(function(){ |
$(this).hide(); |
}); |
}); |
</script> |
</head> |
<body> |
<p>如果你点我,我就会消失。</p> |
<p>继续点我!</p> |
<p>接着点我!</p> |
</body> |
</html> |
jQuery hide()
<!DOCTYPE html> |
<html> |
<head> |
<meta charset="utf-8"> |
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"> |
</script> |
<script> |
$(document).ready(function(){ |
$(".ex .hide").click(function(){ |
$(this).parents(".ex").hide("slow"); |
}); |
}); |
</script> |
<style type="text/css"> |
div.ex |
{ |
background-color:#e5eecc ; |
padding:7px; |
border:solid 1px #c3c3c3 ; |
} |
</style> |
</head> |
<body> |
<h3>Google</h3> |
<div class="ex"> |
<button class="hide">点我隐藏</button> |
<p>站点名: Google<br> |
站点 URL:http://www.google.com</p> |
</div> |
<h3>芝麻教程</h3> |
<div class="ex"> |
<button class="hide">点我隐藏</button> |
<p>站点名: 芝麻教程<br> |
站点 URL:http://www.web3.xin</p> |
</div> |
</body> |
</html> |
通过 jQuery,您可以使用 hide() 和 show() 方法来隐藏和显示 HTML 元素:
<!DOCTYPE html> |
<html> |
<head> |
<meta charset="utf-8"> |
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"> |
</script> |
<script> |
$(document).ready(function(){ |
$("#hide").click(function(){ |
$("p").hide(); |
}); |
$("#show").click(function(){ |
$("p").show(); |
}); |
}); |
</script> |
</head> |
<body> |
<p>如果你点击“隐藏” 按钮,我将会消失。</p> |
<button id="hide">隐藏</button> |
<button id="show">显示</button> |
</body> |
</html> |
$(selector).hide(speed,callback); |
$(selector).show(speed,callback); |
可选的 speed 参数规定隐藏/显示的速度,可以取以下值:"slow"、"fast" 或毫秒。
可选的 callback 参数是隐藏或显示完成后所执行的函数名称。
下面的例子演示了带有 speed 参数的 hide() 方法:
<!DOCTYPE html> |
<html> |
<head> |
<meta charset="utf-8"> |
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"> |
</script> |
<script> |
$(document).ready(function(){ |
$("button").click(function(){ |
$("p").hide(1000); |
}); |
}); |
</script> |
</head> |
<body> |
<button>隐藏</button> |
<p>这是个段落,内容比较少。</p> |
<p>这是另外一个小段落</p> |
</body> |
</html> |
通过 jQuery,您可以使用 toggle() 方法来切换 hide() 和 show() 方法。
显示被隐藏的元素,并隐藏已显示的元素:
<!DOCTYPE html> |
<html> |
<head> |
<meta charset="utf-8"> |
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"> |
</script> |
<script> |
$(document).ready(function(){ |
$("button").click(function(){ |
$("p").toggle(); |
}); |
}); |
</script> |
</head> |
<body> |
<button>隐藏/显示</button> |
<p>这是一个文本段落。</p> |
<p>这是另外一个文本段落。</p> |
</body> |
</html> |
$(selector).toggle(speed,callback); |
可选的 speed 参数规定隐藏/显示的速度,可以取以下值:"slow"、"fast" 或毫秒。
可选的 callback 参数是 toggle() 方法完成后所执行的函数名称。