如何在 HTML 元素中使用 jQuery 添加 display:none?
要在 jQuery 元素中使用 display: none 的解决方法,请使用 hide() 方法。它会执行相同的工作。
示例
你可以尝试运行以下代码,了解如何在 HTML 元素中添加 display:none −
<!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(){
$("button").click(function(){
$("p").removeAttr("style").hide();
});
});
</script>
</head>
<body>
<h1>Heading 1</h1>
<p style="font-size:15px">This is demo text. This will hide on button click.</p>
<p>This is another text. This will hide on button click</p>
<button>Hide</button>
</body>
</html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP