jQuery中的jQuery.hide()和jQuery.remove()方法有什么区别?
jQuery.hide()
如果要隐藏元素,请使用该hide()方法隐藏所选元素。
示例
您可以尝试运行以下代码,以学习如何使用jQuery与jQuery.hide()方法一起使用:
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.staticfile.org/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://cdn.staticfile.org/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>热门推荐
1 训练狗狗搜寻
2 如何训练狗狗装死
3 狗狗训练书
6 怎么训练狗狗拜年
8 狗狗训练游戏
10 狗狗嗅觉训练
11 怎么训练狗狗在笼子里不叫
12 怎么训练狗狗站立走路
13 怎么训练狗狗在马桶上
14 狗狗尿尿怎么训练
15 训练狗狗用品
16 泰迪狗狗的训练方法大小便
17 训练狗狗可以打吗
18 王曼丽的狗狗训练