qq克隆匹配DOM,并选中当前克隆匹配元素集合

来源:互联网 发布:手机挂机赚钱软件 编辑:程序博客网 时间:2024/05/16 19:36

clone( )

克隆匹配DOM,并选中当前克隆匹配元素集合

Html代码 复制代码
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"    
  2.                     "http://www.w3.org/TR/html4/loose.dtd">  
  3. <html>  
  4. <head>  
  5.   <script src="http://code.jquery.com/jquery-latest.js"></script>  
  6.      
  7.   <script>  
  8.   $(document).ready(function(){   
  9.     $("b").clone().prependTo("p");   
  10.   });   
  11.   </script>  
  12.      
  13. </head>  
  14. <body>  
  15.   <b>Hello</b><p>, how are you?</p>  
  16. </body>  

 

$("b").clone().prependTo("p");

将匹配b元素集合克隆,并添加在匹配P元素之前。

 

 

clone( true )

克隆匹配DOM,并获取其事件句柄,选中当前克隆匹配元素集合

Html代码 复制代码
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"    
  2.                     "http://www.w3.org/TR/html4/loose.dtd">  
  3. <html>  
  4. <head>  
  5.   <script src="http://code.jquery.com/jquery-latest.js"></script>  
  6.      
  7.   <script>  
  8.   $(document).ready(function(){   
  9.        
  10.     $("button").click(function(){   
  11.       $(this).clone(true).insertAfter(this);   
  12.     });   
  13.   
  14.   });   
  15.   </script>  
  16.      
  17. </head>  
  18. <body>  
  19.   <button>Clone Me!</button>  
  20. </body>  
  21. </html>  

 

 $(this).clone(true).insertAfter(this);
克隆当前按钮并获取click事件句柄,复制至该按钮后面

原创粉丝点击