回答編集履歴
1
NaN対応
test
CHANGED
@@ -37,3 +37,49 @@
|
|
37
37
|
</table>
|
38
38
|
|
39
39
|
```
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
# NaN対応
|
44
|
+
|
45
|
+
```javascript
|
46
|
+
|
47
|
+
<script>
|
48
|
+
|
49
|
+
window.addEventListener('DOMContentLoaded', function(e){
|
50
|
+
|
51
|
+
var v=[].map.call(document.querySelectorAll('.sample'),function(x){
|
52
|
+
|
53
|
+
return parseFloat(x.textContent)||0;
|
54
|
+
|
55
|
+
}).reduce(function(prev,current){
|
56
|
+
|
57
|
+
return prev+current;
|
58
|
+
|
59
|
+
});
|
60
|
+
|
61
|
+
console.log(v);
|
62
|
+
|
63
|
+
});
|
64
|
+
|
65
|
+
</script>
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
<table>
|
70
|
+
|
71
|
+
<tr>
|
72
|
+
|
73
|
+
<td class = "sample">10</td>
|
74
|
+
|
75
|
+
<td class = "sample">20</td>
|
76
|
+
|
77
|
+
<td class = "sample">30</td>
|
78
|
+
|
79
|
+
<td class = "sample">abc</td>
|
80
|
+
|
81
|
+
</tr>
|
82
|
+
|
83
|
+
</table>
|
84
|
+
|
85
|
+
```
|