回答編集履歴
1
NaN対応
answer
CHANGED
@@ -17,4 +17,27 @@
|
|
17
17
|
<td class = "sample">30</td>
|
18
18
|
</tr>
|
19
19
|
</table>
|
20
|
+
```
|
21
|
+
|
22
|
+
# NaN対応
|
23
|
+
```javascript
|
24
|
+
<script>
|
25
|
+
window.addEventListener('DOMContentLoaded', function(e){
|
26
|
+
var v=[].map.call(document.querySelectorAll('.sample'),function(x){
|
27
|
+
return parseFloat(x.textContent)||0;
|
28
|
+
}).reduce(function(prev,current){
|
29
|
+
return prev+current;
|
30
|
+
});
|
31
|
+
console.log(v);
|
32
|
+
});
|
33
|
+
</script>
|
34
|
+
|
35
|
+
<table>
|
36
|
+
<tr>
|
37
|
+
<td class = "sample">10</td>
|
38
|
+
<td class = "sample">20</td>
|
39
|
+
<td class = "sample">30</td>
|
40
|
+
<td class = "sample">abc</td>
|
41
|
+
</tr>
|
42
|
+
</table>
|
20
43
|
```
|