<body>
<div class="container text-center">
<div class="row">
<div class="col-md-12" style="padding: 50px 0;">
<button type="button" class="btn btn-lg btn-danger" οnclick="add()">添加</button>
</div>
</div>
<div class="row">
<div class="col-md-12">
<form class="form-horizontal">
<!-- <div class="form-group">
<label class="col-sm-1 control-label">姓名</label>
<div class="col-sm-4">
<input type="email" class="form-control" placeholder="请您输入姓名">
</div>
<label class="col-sm-1 control-label">身份证号码</label>
<div class="col-sm-4">
<input type="email" class="form-control" placeholder="请您输入身份证号码">
</div>
<div class="col-sm-2">
<button type="button" οnclick="del(this)" class="btn btn-info">删除</button>
</div>
</div> -->
</form>
</div>
</div>
</div>
<script>
var str = `<div class="form-group">
<label class="col-sm-1 control-label">姓名</label>
<div class="col-sm-4">
<input type="email" class="form-control" placeholder="请您输入姓名">
</div>
<label class="col-sm-1 control-label">身份证号码</label>
<div class="col-sm-4">
<input type="email" class="form-control" placeholder="请您输入身份证号码">
</div>
<div class="col-sm-2">
<button type="button" οnclick="del(this)" class="btn btn-info">删除</button>
</div>
</div>`
$(function() {
var num = prompt('请输入人数')
console.log(parseInt(num));
for (let i = 0; i < parseInt(num); i++) {
$('.form-horizontal').append(str)
}
})
function add() {
$('.form-horizontal').append(str)
}
function del(e) {
console.log(e);
$(e).parents('.form-group').remove()
}
</script>
</body>
</html>