jQuery中显示与隐藏
warning:
这篇文章距离上次修改已过445天,其中的内容可能已经有所变动。
在jQuery中,可以使用.show()和.hide()方法来显示或隐藏元素。
例子:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery Show/Hide Example</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<button id="show">显示</button>
<button id="hide">隐藏</button>
<div id="box" style="width: 100px; height: 100px; background-color: red; display: none;"></div>
<script>
$(document).ready(function(){
$('#show').click(function(){
$('#box').show();
});
$('#hide').click(function(){
$('#box').hide();
});
});
</script>
</body>
</html>在这个例子中,当点击"显示"按钮时,会调用$('#box').show();来显示#box元素,当点击"隐藏"按钮时,会调用$('#box').hide();来隐藏#box元素。
评论已关闭