質問編集履歴
3
言語表示の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -36,7 +36,9 @@
|
|
36
36
|
|
37
37
|
|
38
38
|
|
39
|
+
```html
|
40
|
+
|
39
|
-
|
41
|
+
index.html
|
40
42
|
|
41
43
|
<!DOCTYPE HTML>
|
42
44
|
|
@@ -312,7 +314,9 @@
|
|
312
314
|
|
313
315
|
|
314
316
|
|
315
|
-
```javascript
|
317
|
+
```javascript
|
318
|
+
|
319
|
+
script.js
|
316
320
|
|
317
321
|
coladd = function() {
|
318
322
|
|
@@ -440,7 +444,9 @@
|
|
440
444
|
|
441
445
|
|
442
446
|
|
443
|
-
```javascript
|
447
|
+
```javascript
|
448
|
+
|
449
|
+
util.js
|
444
450
|
|
445
451
|
util = {
|
446
452
|
|
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -36,7 +36,7 @@
|
|
36
36
|
|
37
37
|
|
38
38
|
|
39
|
-
```html
|
39
|
+
```html index.html
|
40
40
|
|
41
41
|
<!DOCTYPE HTML>
|
42
42
|
|
@@ -312,7 +312,7 @@
|
|
312
312
|
|
313
313
|
|
314
314
|
|
315
|
-
```javascript
|
315
|
+
```javascript script.js
|
316
316
|
|
317
317
|
coladd = function() {
|
318
318
|
|
@@ -342,10 +342,6 @@
|
|
342
342
|
|
343
343
|
|
344
344
|
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
345
|
//保存ボタン押下時
|
350
346
|
|
351
347
|
function onSaveButtonClick() {
|
@@ -444,7 +440,7 @@
|
|
444
440
|
|
445
441
|
|
446
442
|
|
447
|
-
```javascript
|
443
|
+
```javascript util.js
|
448
444
|
|
449
445
|
util = {
|
450
446
|
|
1
再現可能なコードを追加致しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,4 +12,486 @@
|
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
-
|
15
|
+
画面を開いた時点では「素材」のプルタブから要素を取得し表示することができます。
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
![イメージ説明](b5cdd9357b74c608024e986e348c0401.png)
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
しかし、「追加」ボタンを押した後に表示されるプルタブからは要素を取得できず、「Uncaught TypeError: Cannot set property 'innerHTML' of undefined」というエラーが表示されてしまいます。
|
24
|
+
|
25
|
+
![イメージ説明](a237af6f3f6c537d2a646be3e16ed419.png)
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
ちなみにプルタブに表示される要素は下記画面のものをとってきています。
|
30
|
+
|
31
|
+
![イメージ説明](3e8a91a4599cea9c98508c60aef70f17.png)
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
コードが長くなってしまい申し訳ございませんが、何かお気づきの点などあればご回答よろしくお願い致します。
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
```html
|
40
|
+
|
41
|
+
<!DOCTYPE HTML>
|
42
|
+
|
43
|
+
<html>
|
44
|
+
|
45
|
+
<head>
|
46
|
+
|
47
|
+
<meta charset="utf-8">
|
48
|
+
|
49
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
|
50
|
+
|
51
|
+
<meta http-equiv="Content-Security-Policy" content="default-src * data: gap: content: https://ssl.gstatic.com; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'">
|
52
|
+
|
53
|
+
<script src="components/loader.js"></script>
|
54
|
+
|
55
|
+
<link rel="stylesheet" href="https://unpkg.com/onsenui/css/onsenui.css">
|
56
|
+
|
57
|
+
<link rel="stylesheet" href="https://unpkg.com/onsenui/css/onsen-css-components.min.css">
|
58
|
+
|
59
|
+
<script src="https://unpkg.com/onsenui/js/onsenui.min.js"></script>
|
60
|
+
|
61
|
+
<link rel="stylesheet" href="components/loader.css">
|
62
|
+
|
63
|
+
<link rel="stylesheet" href="css/style.css">
|
64
|
+
|
65
|
+
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
|
66
|
+
|
67
|
+
<link href="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/css/select2.min.css" rel="stylesheet" />
|
68
|
+
|
69
|
+
<script src="https://cdn.jsdelivr.net/npm/select2@4.0.13/dist/js/select2.min.js"></script>
|
70
|
+
|
71
|
+
</head>
|
72
|
+
|
73
|
+
<body>
|
74
|
+
|
75
|
+
<!-- <ons-navigator swipeable id="myNavigator" page="page1.html"></ons-navigator> -->
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
<ons-tabbar>
|
80
|
+
|
81
|
+
<ons-tab label="計算" page="page1.html">
|
82
|
+
|
83
|
+
</ons-tab>
|
84
|
+
|
85
|
+
<ons-tab label="素材登録" page="page2.html">
|
86
|
+
|
87
|
+
</ons-tab>
|
88
|
+
|
89
|
+
<ons-tab label="素材一覧" page="page3.html">
|
90
|
+
|
91
|
+
</ons-tab>
|
92
|
+
|
93
|
+
</ons-tabbar>
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
<template id="page1.html">
|
98
|
+
|
99
|
+
<ons-page id="page1">
|
100
|
+
|
101
|
+
<ons-toolbar>
|
102
|
+
|
103
|
+
<div class="center">材料費計算</div>
|
104
|
+
|
105
|
+
</ons-toolbar>
|
106
|
+
|
107
|
+
<ons-card class="calcCard">
|
108
|
+
|
109
|
+
<ons-list id="list" modifier="inset">
|
110
|
+
|
111
|
+
<ons-list-header>
|
112
|
+
|
113
|
+
<ons-row>
|
114
|
+
|
115
|
+
<!-- 70 150 100 70 70 -->
|
116
|
+
|
117
|
+
<ons-col>
|
118
|
+
|
119
|
+
<div class="item-title">素材</div>
|
120
|
+
|
121
|
+
</ons-col>
|
122
|
+
|
123
|
+
<ons-col>
|
124
|
+
|
125
|
+
<div class="item-title">商品</div>
|
126
|
+
|
127
|
+
</ons-col>
|
128
|
+
|
129
|
+
<ons-col>
|
130
|
+
|
131
|
+
<div class="item-title">使用量</div>
|
132
|
+
|
133
|
+
</ons-col>
|
134
|
+
|
135
|
+
<ons-col>
|
136
|
+
|
137
|
+
<div class="item-title">小計</div>
|
138
|
+
|
139
|
+
</ons-col>
|
140
|
+
|
141
|
+
<ons-col>
|
142
|
+
|
143
|
+
<div class="item-title"></div>
|
144
|
+
|
145
|
+
</ons-col>
|
146
|
+
|
147
|
+
</ons-row>
|
148
|
+
|
149
|
+
</ons-list-header>
|
150
|
+
|
151
|
+
<ons-list-item>
|
152
|
+
|
153
|
+
<ons-row id="row0" class="row" align="center">
|
154
|
+
|
155
|
+
<!-- 80 150 100 70 50 -->
|
156
|
+
|
157
|
+
<!-- id material数字をつくること -->
|
158
|
+
|
159
|
+
<ons-col>
|
160
|
+
|
161
|
+
<ons-input type="text" id="material0" class="material" value="" modifier="underbar"></ons-input>
|
162
|
+
|
163
|
+
<!-- <ons-select class="selBox" onchange="getSelect(0, this.value)"></ons-select> -->
|
164
|
+
|
165
|
+
<ons-select class="selBox"></ons-select>
|
166
|
+
|
167
|
+
</ons-col>
|
168
|
+
|
169
|
+
<ons-col>
|
170
|
+
|
171
|
+
<ons-input type="tel" id="amount0" class="amount" value="" onchange="changeAmountCalc(this)" modifier="underbar"></ons-input>㌘/ <ons-input type="tel" id="price0" class="price" value="" onchange="changePriceCalc(this)" modifier="underbar"></ons-input>円
|
172
|
+
|
173
|
+
</ons-col>
|
174
|
+
|
175
|
+
<ons-col>
|
176
|
+
|
177
|
+
<ons-input type="tel" id="useAmount0" class="useAmount" value="" onchange="changeUseAmountCalc(this)" modifier="underbar"></ons-input>㌘
|
178
|
+
|
179
|
+
</ons-col>
|
180
|
+
|
181
|
+
<ons-col>
|
182
|
+
|
183
|
+
<span id="sum0" class="sum">0</span>円
|
184
|
+
|
185
|
+
</ons-col>
|
186
|
+
|
187
|
+
<ons-col>
|
188
|
+
|
189
|
+
<ons-button class="delbtn" type="button" id="delBtn1" class="delete" onclick="deleteRow(this)">削除</ons-button>
|
190
|
+
|
191
|
+
</ons-col>
|
192
|
+
|
193
|
+
</ons-row>
|
194
|
+
|
195
|
+
</ons-list-item>
|
196
|
+
|
197
|
+
</ons-list>
|
198
|
+
|
199
|
+
<br>
|
200
|
+
|
201
|
+
<ons-button type="button" id="coladd" onclick="coladd()">追加</ons-button>
|
202
|
+
|
203
|
+
<br><br>
|
204
|
+
|
205
|
+
<div class="total-wrapper">合計:<span id="total">0</span>円</div>
|
206
|
+
|
207
|
+
</ons-card>
|
208
|
+
|
209
|
+
</ons-page>
|
210
|
+
|
211
|
+
</template>
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
<template id="page2.html">
|
216
|
+
|
217
|
+
<ons-page id="page2">
|
218
|
+
|
219
|
+
<ons-toolbar>
|
220
|
+
|
221
|
+
<div class="center">素材登録</div>
|
222
|
+
|
223
|
+
</ons-toolbar>
|
224
|
+
|
225
|
+
<ons-card>
|
226
|
+
|
227
|
+
<div class="inputForm">
|
228
|
+
|
229
|
+
<ons-input class="memoText" modifier="underbar" placeholder="素材を入力"></ons-input>:
|
230
|
+
|
231
|
+
<ons-input type="tel" class="memoText" modifier="underbar" placeholder="グラム数を入力"></ons-input>㌘で
|
232
|
+
|
233
|
+
<ons-input type="tel" class="memoText" modifier="underbar" placeholder="値段を入力"></ons-input>円
|
234
|
+
|
235
|
+
<ons-button id="saveBtn" onclick="onSaveButtonClick()">保存</ons-button>
|
236
|
+
|
237
|
+
</div>
|
238
|
+
|
239
|
+
</ons-card>
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
</ons-page>
|
244
|
+
|
245
|
+
</template>
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
<template id="page3.html">
|
250
|
+
|
251
|
+
<ons-page id="page3">
|
252
|
+
|
253
|
+
<ons-toolbar>
|
254
|
+
|
255
|
+
<div class="center">素材一覧</div>
|
256
|
+
|
257
|
+
</ons-toolbar>
|
258
|
+
|
259
|
+
<ons-list id="memoList">
|
260
|
+
|
261
|
+
<ons-list-header>
|
262
|
+
|
263
|
+
<ons-row>
|
264
|
+
|
265
|
+
<ons-col>
|
266
|
+
|
267
|
+
<div class="item-title">素材</div>
|
268
|
+
|
269
|
+
</ons-col>
|
270
|
+
|
271
|
+
<ons-col>
|
272
|
+
|
273
|
+
<div class="item-title">グラム</div>
|
274
|
+
|
275
|
+
</ons-col>
|
276
|
+
|
277
|
+
<ons-col>
|
278
|
+
|
279
|
+
<div class="item-title">値段</div>
|
280
|
+
|
281
|
+
</ons-col>
|
282
|
+
|
283
|
+
<ons-col>
|
284
|
+
|
285
|
+
<div class="item-title"></div>
|
286
|
+
|
287
|
+
</ons-col>
|
288
|
+
|
289
|
+
</ons-row>
|
290
|
+
|
291
|
+
</ons-list-header>
|
292
|
+
|
293
|
+
</ons-list>
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
</ons-page>
|
298
|
+
|
299
|
+
</template>
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
<script src="js/util.js"></script>
|
304
|
+
|
305
|
+
<script src="js/script.js"></script>
|
306
|
+
|
307
|
+
</body>
|
308
|
+
|
309
|
+
</html>
|
310
|
+
|
311
|
+
```
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
```javascript
|
316
|
+
|
317
|
+
coladd = function() {
|
318
|
+
|
319
|
+
var list = document.getElementById('list');
|
320
|
+
|
321
|
+
var count = list.childElementCount - 1;
|
322
|
+
|
323
|
+
var listItem = document.createElement("ons-list-item");
|
324
|
+
|
325
|
+
var rowItem = document.createElement("ons-row");
|
326
|
+
|
327
|
+
rowItem.setAttribute("id", "row" + count);
|
328
|
+
|
329
|
+
rowItem.setAttribute("class", "row");
|
330
|
+
|
331
|
+
rowItem.setAttribute("align", "center");
|
332
|
+
|
333
|
+
rowItem.innerHTML = '<ons-col><ons-input type="text" id="material' + count + '" class="material" value="" modifier="underbar"></ons-input><ons-select class="selBox" onchange="getSelect(0, this.value)"></ons-select></ons-col><ons-col><ons-input type="tel" id="amount' + count + '" class="amount" value="" modifier="underbar" onchange="changeAmountCalc(this)" ></ons-input>㌘/ <ons-input type="tel" id="price' + count + '" class="price" value="" modifier="underbar" onchange="changePriceCalc(this)"></ons-input>円</ons-col><ons-col><ons-input type="tel" id="useAmount' + count + '" class="useAmount" value="" modifier="underbar" onchange="changeUseAmountCalc(this)"></ons-input>㌘</ons-col><ons-col><span id="sum' + count + '" class="sum">0</span>円</ons-col><ons-col><ons-button class="delbtn" type="button" id="delBtn1" class="delete" onclick="deleteRow(this)">削除</ons-button></ons-col>'
|
334
|
+
|
335
|
+
listItem.appendChild(rowItem);
|
336
|
+
|
337
|
+
list.appendChild(listItem);
|
338
|
+
|
339
|
+
showSelectBox();
|
340
|
+
|
341
|
+
}
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
//保存ボタン押下時
|
350
|
+
|
351
|
+
function onSaveButtonClick() {
|
352
|
+
|
353
|
+
var memos = document.querySelectorAll('.memoText');
|
354
|
+
|
355
|
+
var memoValues = {};
|
356
|
+
|
357
|
+
memoValues.material = memos[0].value;
|
358
|
+
|
359
|
+
memoValues.amount = memos[1].value;
|
360
|
+
|
361
|
+
memoValues.price = memos[2].value;
|
362
|
+
|
363
|
+
util.addItem(memoValues);
|
364
|
+
|
365
|
+
memos[0].value = '';
|
366
|
+
|
367
|
+
memos[1].value = '';
|
368
|
+
|
369
|
+
memos[2].value = '';
|
370
|
+
|
371
|
+
var tabbar = document.querySelector("ons-tabbar")
|
372
|
+
|
373
|
+
tabbar.setActiveTab(2);
|
374
|
+
|
375
|
+
}
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
//各ページが表示された時
|
380
|
+
|
381
|
+
document.addEventListener('show', function(event) {
|
382
|
+
|
383
|
+
var page = event.target;
|
384
|
+
|
385
|
+
//一覧画面が表示された時
|
386
|
+
|
387
|
+
if(page.id === 'page3') {
|
388
|
+
|
389
|
+
//ons-list要素を初期化
|
390
|
+
|
391
|
+
var list = page.querySelector('#memoList');
|
392
|
+
|
393
|
+
list.innerHTML = '';
|
394
|
+
|
395
|
+
//メモの件数分ons-list-item要素を取得
|
396
|
+
|
397
|
+
var items = util.getItems();
|
398
|
+
|
399
|
+
// console.log(itemsLength);
|
400
|
+
|
401
|
+
items.forEach(function(memo, index) {
|
402
|
+
|
403
|
+
ons.createElement('<ons-list-item><ons-row id="materialList-' + index + '"><ons-col class="materialList">' + memo.material + '</ons-col><ons-col class="materialList">' + memo.amount + '㌘</ons-col><ons-col class="materialList">' + memo.price + '円</ons-col><ons-col><ons-button class="delbtn" type="button" id="delBtn1" class="delete" onclick="deleteMaterial(this)">削除</ons-button></ons-col></ons-row></ons-list-item>', {append:list});
|
404
|
+
|
405
|
+
});
|
406
|
+
|
407
|
+
} else if(page.id === 'page1') {
|
408
|
+
|
409
|
+
showSelectBox();
|
410
|
+
|
411
|
+
};
|
412
|
+
|
413
|
+
});
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
function showSelectBox() {
|
418
|
+
|
419
|
+
var items = util.getItems();
|
420
|
+
|
421
|
+
var selBoxies = document.querySelectorAll('.selBox');
|
422
|
+
|
423
|
+
selBoxies.forEach(function(selBox) {
|
424
|
+
|
425
|
+
// window.onload = function() {
|
426
|
+
|
427
|
+
selBox.children[0].innerHTML = '';
|
428
|
+
|
429
|
+
// }
|
430
|
+
|
431
|
+
items.forEach(function(memo) {
|
432
|
+
|
433
|
+
selBox.children[0].append(ons.createElement('<option value="' + memo.material + '">' + memo.material + '</option>'));
|
434
|
+
|
435
|
+
});
|
436
|
+
|
437
|
+
});
|
438
|
+
|
439
|
+
}
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
```
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
```javascript
|
448
|
+
|
449
|
+
util = {
|
450
|
+
|
451
|
+
getItems: function() {
|
452
|
+
|
453
|
+
var items = localStorage.getItem('my_items');
|
454
|
+
|
455
|
+
if(items !== null) {
|
456
|
+
|
457
|
+
// console.log(items);
|
458
|
+
|
459
|
+
return JSON.parse(items);
|
460
|
+
|
461
|
+
} else {
|
462
|
+
|
463
|
+
return [];
|
464
|
+
|
465
|
+
}
|
466
|
+
|
467
|
+
},
|
468
|
+
|
469
|
+
addItem: function(memo) {
|
470
|
+
|
471
|
+
var items = this.getItems();
|
472
|
+
|
473
|
+
// console.log(items);
|
474
|
+
|
475
|
+
items.unshift(memo);
|
476
|
+
|
477
|
+
// console.log(memo);
|
478
|
+
|
479
|
+
localStorage.setItem('my_items', JSON.stringify(items));
|
480
|
+
|
481
|
+
},
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
deleteItem: function(index) {
|
486
|
+
|
487
|
+
var items = this.getItems();
|
488
|
+
|
489
|
+
items.splice(index, 1);
|
490
|
+
|
491
|
+
localStorage.setItem('my_items', JSON.stringify(items));
|
492
|
+
|
493
|
+
}
|
494
|
+
|
495
|
+
}
|
496
|
+
|
497
|
+
```
|