回答編集履歴
2
修正
answer
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
<script>
|
5
5
|
window.addEventListener('DOMContentLoaded', function(e){
|
6
6
|
var num=Array.prototype.map.call(document.querySelectorAll('[name="k-subtotal"]'),function(x){
|
7
|
-
return parseInt(x.value);
|
7
|
+
return parseInt(x.value)||0; /*一部エラー回避処理を追記*/
|
8
8
|
}).reduce(function(x,y) {
|
9
9
|
return x+y;
|
10
10
|
});
|
1
調整
answer
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
こういう感じでしょうか?
|
2
2
|
|
3
3
|
```javascript
|
4
|
+
<script>
|
4
5
|
window.addEventListener('DOMContentLoaded', function(e){
|
5
|
-
var num=Array.prototype.map.call(document.querySelectorAll(
|
6
|
+
var num=Array.prototype.map.call(document.querySelectorAll('[name="k-subtotal"]'),function(x){
|
6
7
|
return parseInt(x.value);
|
7
8
|
}).reduce(function(x,y) {
|
8
9
|
return x+y;
|
9
10
|
});
|
10
11
|
console.log(num);
|
11
12
|
});
|
12
|
-
```
|
13
|
-
|
13
|
+
</script>
|
14
14
|
<input type="text" name="k-subtotal" value="100">
|
15
15
|
<input type="text" name="k-subtotal" value="150">
|
16
16
|
<input type="text" name="k-subtotal" value="200">
|
17
17
|
|
18
|
-
```
|
18
|
+
```
|
19
|
+
|
20
|
+
※わかりやすくするためソースを結合
|