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>热门推荐
10 早日回国祝福语简短英语
11 三八简短祝福语给婆婆
12 护士辞职送行祝福语简短
13 姐姐生日祝福语漂亮简短
14 38节贺卡简短祝福语
15 宝宝周岁敬酒祝福语简短
16 男童毕业蛋糕祝福语简短
17 生日涂鸦祝福语简短英文
18 写给男生简短的祝福语