问题描述
JQ 如何嵌套 动态删除与新增input框,但一层点击新增删除input框都OK。现在问题是套一层。
相关代码
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JQ动态删除与新增input框</title>
<link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.css">
<script src="https://cdn.bootcss.com/jquery/1.11.3/jquery.min.js" type="text/javascript"></script>
<style>
.spot{float: left;width:200px;height: 40px;}
</style>
</head>
<body>
<input type="button" id="" value="增加一个表"/>
<div id="spots">
<input type="text" name="" placeholder="请输入表名">
<input type="button" id="add" name="add" value="增加字段"/>
<input type="button" id="del" name="del" value="删除表"/><br/>
</div>
<script type="text/javascript">
$(document).ready(function () {
$("input#add").click(function () {
$('div#spots').append(
'<div class="spot">' +
'<input type="text" name="ckname" /> ' +
'<i class="fa fa-minus-circle" id="del" style="cursor:pointer;color:#FF1F1F"></i>' +
'</div>'
)
.find("i#del").click(function () {
$(this).parent().remove();
});
});
$("input#del").click(function () {
$('div#spots').remove();
});
})
</script>
</body>
</html>
还是自己回答自己问题吧!
直接拿去用,哈哈哈!
<html>
<head>
</head>
<body>
</body>
</html>
放一个成品:
