clone()函数的true属性

<!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>
        <meta charset="utf-8" />
        <style type="text/css">
            #main {
                width: 300px;
                margin: 200px auto;
                background-color: gold;
                padding: 10px;
            }
        </style>
        <script src="js/JQ3.3.1.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>

 

posted on 2018-04-19 17:07  三盛乙烯  阅读(156)  评论(0编辑  收藏  举报

导航