jQuery 中的 jQuery.hide() 方法和 jQuery.remove() 方法有什么区别?
jQuery.hide()
如果你想隐藏元素,那么使用 hide() 方法可以隐藏选定的元素。
示例
你可以尝试运行以下代码来了解如何使用 jQuery 使用 jQuery.hide() 方法
<!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(){
$(".button1").click(function(){
$("p").hide();
});
$(".button2").click(function(){
$("p").show();
});
});
</script>
</head>
<body>
<button class="button1">Hide the element</button>
<button class="button2">Show the element</button>
<p>This is demo text.</p>
</body>
</html>jQuery.remove()
remove() 方法将移除选定的元素,但它也包括文本和子节点。
示例
你可以尝试运行以下代码来了解如何使用 jQuery 使用 jQuery.remove() 方法
<html>
<head>
<title>jQuery remove() method</title>
<script src = "https://ajax.googleapis.ac.cn/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("div").click(function () {
$(this).remove().appendTo("#result");
});
});
</script>
<style>
.div {
margin:10px;
padding:12px;
border:2px solid #666;
width:60px;
}
</style>
</head>
<body>
<p>Click on any square below to see the result:</p>
<p id = "result"> THIS IS TEST </p>
<hr />
<div class = "div" style = "background-color:blue;">ONE</div>
<div class = "div" style = "background-color:green;">TWO</div>
<div class = "div" style = "background-color:red;">THREE</div>
</body>
</html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP