标签:sel query append har html javascrip ext 实现 his
简单实现文本框的插入与移除:
HTML代码块:
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <title>Title</title>
6 </head>
7 <body>
8 <script src="jquery-3.3.1.min.js"></script>
9 <script src="clone.js"></script>
10
11 <div class="box">
12 <div class="item">
13 <button onclick="add(this)">+</button>
14 <input type="text" >
15 </div>
16
17 </div>
18 </body>
19 </html>
JavaScript的代码块:
1 function add(self) {
2 var $clo_obj=$(self).parent().clone();
3 $clo_obj.children("button").html("-").attr("onclick","del_obj(this)");
4 $(".box").append($clo_obj);
5 }
6 function del_obj(self) {
7 $(self).parent().remove()
8 }
标签:sel query append har html javascrip ext 实现 his
原文地址:https://www.cnblogs.com/wen-kang/p/9482671.html