質問編集履歴
1
修正
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -38,13 +38,13 @@
|
|
|
38
38
|
```
|
|
39
39
|
<script>
|
|
40
40
|
$(document).on('click', '#add_group', function() {
|
|
41
|
-
|
|
41
|
+
//要素の数をカウントして、複製したフォームのnameを変更する
|
|
42
|
-
classLength = $('[id^=group]').length;
|
|
42
|
+
classLength = $('[id^=group]').length; //要素数 1, 2
|
|
43
|
-
selector = "#group"+(classLength);
|
|
43
|
+
selector = "#group"+(classLength); //1つ前のID名 #group1, 2
|
|
44
|
-
newSelector = "group"+(classLength + 1);
|
|
44
|
+
newSelector = "group"+(classLength + 1); //新しいID group2,3
|
|
45
|
-
|
|
45
|
+
//クローン処理
|
|
46
46
|
$(clone).clone(true).insertAfter(selector).attr('id', newSelector);
|
|
47
|
-
|
|
47
|
+
//複製したものに関する調整処理
|
|
48
48
|
$("#" + newSelector).find("input").each(function(i, elm){
|
|
49
49
|
elm.name = elm.name.replace(/[[0-9]+]/, '[' + classLength + ']');
|
|
50
50
|
elm.id = elm.id.replace(/\-[0-9]+\-/, '-' + classLength + '-');
|