jquery的显示和隐藏
一、jquery的 hide() 和 show()
hide() 隐藏 , show() 显示
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p id="p1">如果点击“隐藏”按钮,我就会消失。</p>
<button id="hide" type="button">隐藏</button>
<button id="show" type="button">显示</button>
</body>
</html>
<script src="/jquery/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#hide").click(function(){
$("#p1").hide();
});
$("#show").click(function(){
$("#p1").show();
});
});
</script>
二、jquery的 toggle()
toggle() 可以来回切换 hide() 和 show() 方法
显示被隐藏的元素,并隐藏已显示的元素:
<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").toggle();
});
});
</script>
</head>
<body>
<button type="button">切换</button>
<p>这是一个段落。</p>
<p>这是另一个段落。</p>
</body>
</html>
本文介绍了使用 jQuery 实现元素的显示与隐藏效果。通过 hide() 和 show() 方法实现基本的隐藏与显示功能,toggle() 方法则用于在两者之间进行切换。提供了具体的 HTML 结构与 JavaScript 代码实例。

4305

被折叠的 条评论
为什么被折叠?



