- clone(): Clone the matched DOM element and return the cloned copy, but the cloned new node does not have any behavior.
Example 1:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>克隆节点</title>
<script src="jquery-1.11.3.js"></script>
</head>
<body>
<ul id="fruit">
<li title="pg">苹果</li>
<li title="jz">橘子</li>
<li title="xj">香蕉</li>
</ul>
<script>
$(function(){
$("li").click(function(){
var $fruit=$("#fruit");
var $li=$(this).clone();
$fruit.append($li);
});
})
</script>
</body>
</html>
- clone(true): The copied element also copies the event in the element.
Example 2:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>克隆节点</title>
<script src="jquery-1.11.3.js"></script>
</head>
<body>
<ul id="fruit">
<li title="pg">苹果</li>
<li title="jz">橘子</li>
<li title="xj">香蕉</li>
</ul>
<script>
$(function(){
$("li").click(function(){
var $fruit=$("#fruit");
var $li=$(this).clone(true);
$fruit.append($li);
});
})
</script>
</body>
</html>