<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title></title>
<script src="../jquery-1.10.2.min.js"></script>
<script type="text/javascript">
/*remove:移除节点
1.无参数,移除自身整个节点以及该节点的内部的所有节点,包括节点上事件与数据
2.有参数,移除筛选出的节点以及该节点的内部的所有节点,包括节点上事件与数据
detach:移除节点
1.移除的处理与remove一致
2.与remove()不同的是,所有绑定的事件、附加的数据等都会保留下来
3.例如:$("p").detach()这一句会移除对象,仅仅是显示效果没有了。但是内存中还是存在的。当你append之后,又重新回到了文档流中。就又显示出来了。*/
$(document).ready(function() {
$(".aa").on('click', function(){
$(".aa").remove();//删除aa下的所有元素
})
var p;
$(".bb").click(function() {
//通过detach方法删除元素
//只是页面不可见,但是这个节点还是保存在内存中
//数据与事件都不会丢失
p = $(".bb").detach()
})
$(".but").click(function() {
//把p元素在添加到页面中
//事件还是存在
$("body").append(p);
});
});
</script>
<style>
.aa{
width:150px;
height:150px;
margin:10px;
background-color:red;
}
.bb{
width:150px;
height:150px;
margin:10px;
background-color:green;
}
</style>
</head>
<body>
<div class="aa">
<span>大姑娘</span>
<span>小姑娘</span>
</div>
<div class="bb">
<span>大姑娘</span>
<span>小姑娘</span>
</div>
<button class="but">点击</button>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta