实例 jQuery 如何使用 clone() 方法复制元素,包括事件处理程序

x
 
<!DOCTYPE html>
<html>
<head>
<script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("body").append($("p:first").clone(true));
  });
  $("p").click(function(){
    $(this).animate({fontSize: "+=1px"});
  });
});
</script>
</head>
<body>
<p>Click this paragraph to increase text size.</p>
<p>This is another paragraph.</p>
<button>Copy the first p element (including event handlers), and append to body element</button>
</body>
</html>
                    

输出结果