jquery的clon

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="jquery-3.1.1.js"></script>
</head>
<body>
<div id="tianjiaclon">
    <div id="ddddd">
        <input type="button" value="+" onclick="f(this)">
        <input type="text">
    </div>
</div>
</body>
    <script>
        function f(self) {
            var s = $(self).parent().clone(); //获取到this的点击事件后,返回父标签,进行clon

            //把clon出来的标签的"+"号变为"-"号
            s.children(":button").val("-").attr("onclick","f1(this)");

            $("#tianjiaclon").append(s);  //把clon的信息添加到,最外层的div标签中



        }

        function f1(self) {
               //点击"-"号把clon当前对象删除
            $(self).parent().remove();
        }

    </script>
</html>

相关推荐