回答編集履歴
2
ちょうせい
test
CHANGED
@@ -37,8 +37,6 @@
|
|
37
37
|
$(this).attr('name',name);
|
38
38
|
|
39
39
|
});
|
40
|
-
|
41
|
-
console.log(dom.html())
|
42
40
|
|
43
41
|
dom.appendTo($('#hogehuga'));
|
44
42
|
|
1
sample
test
CHANGED
@@ -3,3 +3,105 @@
|
|
3
3
|
まっとうに動かすことはできません
|
4
4
|
|
5
5
|
idの付け方を抜本的に検討し直してください
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
# sample
|
10
|
+
|
11
|
+
```javascript
|
12
|
+
|
13
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
|
14
|
+
|
15
|
+
<script>
|
16
|
+
|
17
|
+
$(function() {
|
18
|
+
|
19
|
+
$('#addBtn').click(function(e) {
|
20
|
+
|
21
|
+
var cnt =$('#hogehuga [id^=hogeNm_]').length;
|
22
|
+
|
23
|
+
var dom=$('#hogehuga div:last-child').clone(true);
|
24
|
+
|
25
|
+
dom.find('select[id],input[id]').each(function(){
|
26
|
+
|
27
|
+
var id=$(this).attr('id').replace(/_([0-9]+)$/g,'_'+cnt);
|
28
|
+
|
29
|
+
$(this).attr('id',id);
|
30
|
+
|
31
|
+
});
|
32
|
+
|
33
|
+
dom.find('select[name],input[name]').each(function(){
|
34
|
+
|
35
|
+
var name=$(this).attr('name').replace(/_([0-9]+)$/g,'_'+cnt);
|
36
|
+
|
37
|
+
$(this).attr('name',name);
|
38
|
+
|
39
|
+
});
|
40
|
+
|
41
|
+
console.log(dom.html())
|
42
|
+
|
43
|
+
dom.appendTo($('#hogehuga'));
|
44
|
+
|
45
|
+
});
|
46
|
+
|
47
|
+
});
|
48
|
+
|
49
|
+
</script>
|
50
|
+
|
51
|
+
<table>
|
52
|
+
|
53
|
+
<tbody>
|
54
|
+
|
55
|
+
<tr>
|
56
|
+
|
57
|
+
<td>
|
58
|
+
|
59
|
+
<input type="button" name="addBtn" id="addBtn" value="追加" />
|
60
|
+
|
61
|
+
</td>
|
62
|
+
|
63
|
+
<td id="hogehuga">
|
64
|
+
|
65
|
+
<?php
|
66
|
+
|
67
|
+
$count=3;
|
68
|
+
|
69
|
+
for ( $i = 0; $i < $count; $i++ ) {
|
70
|
+
|
71
|
+
?>
|
72
|
+
|
73
|
+
<div>
|
74
|
+
|
75
|
+
<input type="text" id="hogeNm_<?= $i ?>" name="hogeNm_<?= $i ?>" />
|
76
|
+
|
77
|
+
<select id="hogeSel_<?= $i ?>" name="hogeSel_<?= $i ?>">
|
78
|
+
|
79
|
+
<option value="0">hoge</option>
|
80
|
+
|
81
|
+
<option value="1">huga</option>
|
82
|
+
|
83
|
+
</select>
|
84
|
+
|
85
|
+
<input type="checkbox" id="hogeChk_0_<?= $i ?>" name="hogeChk_0_<?= $i ?>" />hoge
|
86
|
+
|
87
|
+
<input type="checkbox" id="hugaChk_1_<?= $i ?>" name="hugaChk_1_<?= $i ?>" />huga
|
88
|
+
|
89
|
+
<input type="button" name="btnGO" value="GO" />
|
90
|
+
|
91
|
+
</div>
|
92
|
+
|
93
|
+
<?php
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
?>
|
98
|
+
|
99
|
+
</td>
|
100
|
+
|
101
|
+
</tr>
|
102
|
+
|
103
|
+
</tbody>
|
104
|
+
|
105
|
+
</table>
|
106
|
+
|
107
|
+
```
|