jQuery copy node
clone([false])Default: only copy the object node
clone(true): Copy the element node and its corresponding events, set to true to copy all event processing of the element
<!DOCTYPE html> <html> <head> <title>php.cn</title> <meta charset="utf-8" /> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script> $(document).ready(function(){ //给#big的每个li设置click事件css() attr() //click()方法本身有遍历机制,会为每个li都设置click事件 //每个li都会绑定一个click事件(会为每个li执行一次click内部的function) $("#big li").click(function(){ //单击弹出对应的文本信息 alert($(this).html()); }); }); function f1(){ //var fu_guan = $('#guan').clone(false); //只复制“节点” var fu_guan = $('#guan').clone(true); //“节点”和“其事件”都复制 $("#small").append(fu_guan); } </script> <style type="text/css"> div {width:300px; height:200px; background-color:pink;} </style> </head> <body> <ul id="big"> <li>A</li> <li>B</li> <li id="guan">C</li> </ul> <ul id="small"> <li>a</li> <li>b</li> <li id="gai">c</li> </ul> <input type="button" value="复制" onclick="f1()" /> </body> </html>