detach()方法的作用是移除被选的元素(包括所有文本和字节点),
但是这个方法会保留备选的元素,因而可以再次使用这些元素和它绑定的事件。
以下三个例子将详细解释detach()方法
<html>
<head>
<script type = "text/javascript" src = "../jquery/jquery.js"></script>
<script type = "text/javascript" >
$(document).ready(function(){
var x;
$("#bt1").click(function(){
x = $("p").detach();
});
$("#bt2").click(function(){
$("body").append(x);
});
$("p").click(function(){
$(this).animate({fontSize:"+=1px"});
});
});
</script>
</head>
<body>
<p>我就是小P,请我回来之后,点我有变化</p>
<button id = "bt1">移除小P</button>
<button id = "bt2">请回小P</button>
</body>
</html>