http://superkts.pe.kr/helper/view.php?seq=V&seq=290
처럼 a,b,c,d 로 나누어서
a팀 버튼클릭시 필드 계속 추가 <input name="awr_1">, 버튼클릭 <input name="awr_2"> ...
b팀 버튼클릭시 필드 계속 추가 <input name="bwr_1">, 버튼클릭 <input name="bwr_2"> ...
c팀 버튼클릭시 필드 계속 추가 <input name="cwr_1">, 버튼클릭 <input name="cwr_2">
d팀 버튼클릭시 필드 계속 추가 <input name="dwr_1">, 버튼클릭 <input name="dwr_2">
이렇게 만들고 싶은데 혹시 스킨이나 예제 등이 있는지 질문드립니다 ^^;
답변 1개 / 댓글 1개
채택된 답변
+20 포인트
2017-11-30 (목) 23:40:55
Copy
<script type="text/javascript">
$(function() {
var c = "", n, nn;
$("input[type='button']").on("click", function() {
c = $(this).prev("input").attr("name").split("_");
n = $(this).siblings("input[name^='" + c[0] + "']:last").attr("name").split("_");
nn = parseInt(n[1]) > 1 ? parseInt(n[1]) + 1 : 2;
$(this).parent("div").append("<input type='text' name='" + c[0] + "_" + nn + "' /><input type='button' value='삭제' class='rem' />");
});
$("body").on("click", "input.rem", function() {
$(this).prev().remove();
$(this).remove();
});
});
</script>
<div><input type="text" name="awr_1" /><input type="button" value="추가" /></div>
<div><input type="text" name="bwr_1" /><input type="button" value="추가" /></div>
<div><input type="text" name="cwr_1" /><input type="button" value="추가" /></div>
<div><input type="text" name="dwr_1" /><input type="button" value="추가" /></div>
js로 하면 길어지고 해서 jquery로...
답변에 대한 댓글 1개
답변을 작성하려면 로그인이 필요합니다.