当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jQuery实现基本隐藏与显示效果的方法详解

jQuery实现基本隐藏与显示效果的方法详解

2018年09月24日  | 移动技术网IT编程  | 我要评论

本文实例讲述了jquery实现基本隐藏与显示效果的方法。分享给大家供大家参考,具体如下:

jquery 隐藏/显示

语法:

$(selector).hide(speed,callback);
$(selector).show(speed,callback);

eg1:

<!doctype html>
<html>
<head>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p").click(function(){
$(this).hide();
});
});
</script>
</head>
<body>
<p>田xx,我爱你。</p>
<p>傻x,田xx。</p>
<p>滚x,田xx。</p>
</body>
<html>

运行结果:

eg2:

<!doctype html>
<html>
<head>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
$(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>我爱你</h3>
<div class="ex">
<button class="hide" type="button">隐藏</button>
<p>姓名:田xx <br />
田大大<br />
田傻逼</p>
</div>
</body>
<html>

运行结果:

jquery toggle()

使用toggle()方法来切换hide()show()方法。

<!doctype html>
<html>
<head>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 $("button").click(function(){
 $("p").toggle();
 });
});
</script>
</head>
<body>
<button type="button">切换</button>
<p>这是个段落</p>
</body>
<html>

运行结果:

感兴趣的朋友可以使用在线html/css/javascript代码运行工具测试上述代码运行效果。

更多关于jquery相关内容还可查看本站专题:《jquery切换特效与技巧总结》、《jquery扩展技巧总结》、《jquery常用插件及用法总结》、《jquery拖拽特效与技巧总结》、《jquery表格(table)操作技巧汇总》、《jquery常见经典特效汇总》、《jquery动画与特效用法总结》及《jquery选择器用法总结

希望本文所述对大家jquery程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网