时间:2021-07-01 10:21:17 帮助过:28人阅读
本文实例讲述了jQuery中hide()方法用法。分享给大家供大家参考。具体分析如下:
此方法可以将匹配元素隐藏。
hide()方法的用法:
此方法如果没有对隐藏效果加以时间限定,那么匹配元素会被瞬间隐藏。例如:
代码如下:
$("p").hide()
以上代码可以将所有p元素瞬间隐藏。
如果方法对隐藏效果加以时间限定,那么匹配元素将会在限定的事件内以比较优雅的形式隐藏。例如:
代码如下:
$("p").hide(2000)
以上代码可以将所有p元素在2000毫秒(2秒)内隐藏。
此方法也可以在隐藏完成后触发一个回调函数。例如:
代码如下:
$("p").hide(2000,function(){alert("我隐藏好了")});
实例代码:
代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.gxlcms.com/" />
<title>hide()函数-脚本之家</title>
<style type="text/css">
p{
color:blue;
background-color
:green;
width:100px;
height:100px;
margin-top
:10px;
}
</style>
<script type="text/
javascript
" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(
document
).ready(function(){
$("#first").click(function(){
$(".first").hide();
})
$("#second").click(function(){
$(".second").hide(2000,function(){alert("我隐藏好了")});
})
})
</script>
</head>
<body>
<p class="first"></p>
<p class="second"></p>
<button id="first">瞬间隐藏</button>
<button id="second">优雅的隐藏</button>
</body>
</html>以上代码能够在隐藏完成以后触发回调函数,于是弹出一个提示框。
以上就是有关jQuery中hide()方法用法实例详解的详细内容,更多请关注Gxl网其它相关文章!