質問編集履歴

1

追記

2019/03/25 04:39

投稿

tkshp
tkshp

スコア174

test CHANGED
File without changes
test CHANGED
@@ -79,3 +79,93 @@
79
79
  となるので、
80
80
 
81
81
  これで何故、val.text()でエラーが出てしまうのかわかりません。
82
+
83
+
84
+
85
+ ### 追記
86
+
87
+
88
+
89
+ 現状の全コードです。
90
+
91
+
92
+
93
+ ```html
94
+
95
+ <!DOCTYPE html>
96
+
97
+ <html>
98
+
99
+ <head>
100
+
101
+ <meta charset="UTF-8">
102
+
103
+ <title>sample page</title>
104
+
105
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
106
+
107
+ <script src="sample01.js"></script>
108
+
109
+ <!-- <link rel="stylesheet" type="text/css" href="sample01.css"> -->
110
+
111
+ </head>
112
+
113
+ <body>
114
+
115
+ <table>
116
+
117
+ <tr>
118
+
119
+ <td class = "sample">10</td>
120
+
121
+ <td class = "sample">20</td>
122
+
123
+ <td class = "sample">30</td>
124
+
125
+ </tr>
126
+
127
+ </table>
128
+
129
+ </body>
130
+
131
+ </html>
132
+
133
+ ```
134
+
135
+
136
+
137
+ ```JavaScript
138
+
139
+ $(function(){
140
+
141
+ var sum;
142
+
143
+ $(".sample").each(function(index, val){
144
+
145
+ console.log($(val).text());
146
+
147
+ sum += parseInt($(val).text(), 10);
148
+
149
+ });
150
+
151
+ console.log(sum);
152
+
153
+ });
154
+
155
+ ```
156
+
157
+
158
+
159
+ ・出力結果。
160
+
161
+ ```
162
+
163
+ 10
164
+
165
+ 20
166
+
167
+ 30
168
+
169
+ NaN
170
+
171
+ ```