您现在的位置: 万盛学电脑网 >> 程序编程 >> 脚本专题 >> javascript >> 正文

JQuery中clone方法复制节点

作者:佚名    责任编辑:admin    更新时间:2022-06-22

   本文实例讲述了JQuery中clone方法复制节点。分享给大家供大家参考。具体如下:

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>复制节点</title> <style type="text/css"> #main{ width:300px; margin:200px auto; background-color:gold; padding:10px; } </style> <script src="js/jquery-1.5.1.min.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { var $text = $("#txt1"); $text.click(function () { alert('我是文本框单击事件'); }); $("#btn1").click(function () { $("#btn1").after($text.clone()); //浅克隆(不复制事件) }); $("#btn2").click(function () { $("#btn2").after($text.clone(true)); //深克隆(复制事件) }); }); </script> </head> <body> <div id="main"> <input type="text" value="我是文本框" id="txt1" /> <input type="button" id="btn1" value="进行浅克隆(不复制事件)" /> <input type="button" id="btn2" value="进行深克隆(复制事件)" /> </div> </body> </html>

  希望本文所述对大家的jQuery程序设计有所帮助。