预览效果
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<button id="add">新增</button>
<div class="container">
<section>
<label>姓名</label>
<input type="text">
<label>关系</label>
<input type="text">
<label>电话</label>
<input type="text">
</section>
<section>
<label>姓名</label>
<input type="text">
<label>关系</label>
<input type="text">
<label>电话</label>
<input type="text">
<button class="del">删除</button>
</section>
</div>
<script src="./jquery-3.2.1.min.js"></script>
<script src="./global.js"></script>
</body>
</html>
js
$(function () {
// 模板字符串
let box = `<section>
<label>姓名</label>
<input type="text">
<label>关系</label>
<input type="text">
<label>电话</label>
<input type="text">
<button class="del">删除</button>
</section>`;
// 增加节点
$('#add').click(() => {
$('.container').append(box);
});
// 删除对应节点
$(document).on('click', '.del', function () {
$(this).parent().remove();
});
})