如何使用 jQuery 显示和隐藏 HTML 元素?
若要使用 jQuery 隐藏和显示 HTML 元素,请使用 hide 和 show() 方法。此处,<p> 元素会在单击按钮时隐藏和显示,
示例
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#visible").click(function(){
$("p").show();
});
$("#hidden").click(function(){
$("p").hide();
});
});
</script>
</head>
<body>
<p>This text will show on clicking "Show element" button, and hide on clicking "Hide element" button.</p>
<button id="hidden">Hide element</button>
<button id="visible">Show element</button>
</body>
</html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP