回答編集履歴
1
追記
test
CHANGED
@@ -17,3 +17,141 @@
|
|
17
17
|
> value string: Returns / Sets the current value of the control.
|
18
18
|
|
19
19
|
[HTMLInputElement - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement)
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
##### コメントを受けて追記
|
30
|
+
|
31
|
+
```HTML
|
32
|
+
|
33
|
+
<table id="tbl">
|
34
|
+
|
35
|
+
<tr>
|
36
|
+
|
37
|
+
<td>
|
38
|
+
|
39
|
+
<select id="number1">
|
40
|
+
|
41
|
+
<option>001</option>
|
42
|
+
|
43
|
+
<option>002</option>
|
44
|
+
|
45
|
+
</select>
|
46
|
+
|
47
|
+
</td>
|
48
|
+
|
49
|
+
<td>
|
50
|
+
|
51
|
+
<input type="text" id="txt1">
|
52
|
+
|
53
|
+
</td>
|
54
|
+
|
55
|
+
</tr>
|
56
|
+
|
57
|
+
<tr>
|
58
|
+
|
59
|
+
<td>
|
60
|
+
|
61
|
+
<select id="number2">
|
62
|
+
|
63
|
+
<option>001</option>
|
64
|
+
|
65
|
+
<option>002</option>
|
66
|
+
|
67
|
+
</select>
|
68
|
+
|
69
|
+
</td>
|
70
|
+
|
71
|
+
<td>
|
72
|
+
|
73
|
+
<input type="text" id="txt2">
|
74
|
+
|
75
|
+
</td>
|
76
|
+
|
77
|
+
</tr>
|
78
|
+
|
79
|
+
</table>
|
80
|
+
|
81
|
+
<button>
|
82
|
+
|
83
|
+
test
|
84
|
+
|
85
|
+
</button>
|
86
|
+
|
87
|
+
```
|
88
|
+
|
89
|
+
```javascript
|
90
|
+
|
91
|
+
var tblData = document.getElementById("tbl");
|
92
|
+
|
93
|
+
document.querySelector('button').addEventListener('click', e => {
|
94
|
+
|
95
|
+
let txtTbldata = '';
|
96
|
+
|
97
|
+
for (var i = 0, rowlen = tblData.rows.length; i < rowlen; i++) {
|
98
|
+
|
99
|
+
for (var j = 0, collen = tblData.rows[i].cells.length; j < collen; j++) {
|
100
|
+
|
101
|
+
txtTbldata += tblData.rows[i].cells[j].children[0].value;
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
alert(txtTbldata);
|
108
|
+
|
109
|
+
})
|
110
|
+
|
111
|
+
```
|
112
|
+
|
113
|
+
[https://jsfiddle.net/pg14qncq/](https://jsfiddle.net/pg14qncq/)
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
こんな感じでいかが。
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
さらに行を少なくするなら、ワンライナーで書けますよ。
|
126
|
+
|
127
|
+
```javascript
|
128
|
+
|
129
|
+
document.querySelector('button').addEventListener(
|
130
|
+
|
131
|
+
'click',
|
132
|
+
|
133
|
+
e => alert(
|
134
|
+
|
135
|
+
Array.prototype.reduce.call(
|
136
|
+
|
137
|
+
document.getElementById("tbl").rows,
|
138
|
+
|
139
|
+
( pv, cv ) => pv + Array.prototype.reduce.call(
|
140
|
+
|
141
|
+
cv.cells,
|
142
|
+
|
143
|
+
( pv, cv ) => pv + cv.children[0].value,
|
144
|
+
|
145
|
+
''
|
146
|
+
|
147
|
+
),
|
148
|
+
|
149
|
+
''
|
150
|
+
|
151
|
+
)
|
152
|
+
|
153
|
+
)
|
154
|
+
|
155
|
+
);
|
156
|
+
|
157
|
+
```
|