teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

5

説明文に3ファイルとも修正した旨記載を追加

2020/10/10 03:40

投稿

nekora
nekora

スコア501

answer CHANGED
@@ -15,6 +15,7 @@
15
15
 
16
16
  ### CSSが開示されたので動作確認をし、不具合やUIの利便性などを修正してあります。
17
17
  ### 以下が修正した、完全動作版のソースコードです。
18
+ **3つのファイル全てに手を入れてるので全てお持ちのコードと差し替えてください。**
18
19
 
19
20
  ```html
20
21
  <!DOCTYPE html>

4

CSSの更新

2020/10/10 03:40

投稿

nekora
nekora

スコア501

answer CHANGED
@@ -261,86 +261,89 @@
261
261
  css/styles.css
262
262
  ```css
263
263
  body {
264
- margin: 0;
264
+ margin: 0;
265
- }
265
+ }
266
-
266
+
267
- .container {
267
+ .container {
268
- display: flex;
268
+ display: flex;
269
- justify-content: center;
269
+ justify-content: center;
270
- }
270
+ }
271
-
271
+
272
- .table1 {
272
+ .table1 {
273
- width: 80%;
273
+ width: 80%;
274
- }
274
+ }
275
-
275
+
276
- .thisMonth {
276
+ .thisMonth {
277
- text-align: center;
278
- margin: 40px auto;
279
- }
280
-
281
- .sat {
282
- background-color: skyblue;
283
- }
284
-
285
- .sun {
286
- background-color: tomato;
287
- }
288
-
289
- #prev,
290
- #next {
291
- display: block;
292
- margin: auto;
293
- padding: 10px; /* 押しづらいのでpaddingで押せる領域を広げてやる */
294
- border: 1px solid black;
295
- cursor: pointer;
296
- }
297
-
298
- /* 押せる範囲に入ったら背景色を変えて教えてやると使い勝手が上がる */
299
- #prev:hover,
300
- #next:hover {
301
- background-color: yellow;
302
- }
303
-
304
- .heading {
305
- display: flex;
306
- }
307
-
308
- .header {
309
- font-weight: bold;
310
- }
311
-
312
- .btn {
313
- margin-left: 150px;
314
- margin-bottom: 20px;
315
- }
316
-
317
- table,
318
- th,
319
- tr,
320
- td {
321
- border-collapse: collapse;
322
- border: 2px solid #333;
323
- }
324
-
325
- td {
326
- width: 53px;
327
- height: 28px;
328
277
  text-align: center;
278
+ margin: 40px auto;
329
- }
279
+ }
280
+
281
+ .sat {
282
+ background-color: skyblue;
283
+ }
284
+
285
+ .sun {
286
+ background-color: tomato;
287
+ }
288
+
289
+ #prev,
290
+ #next {
291
+ display: block;
292
+ margin: auto;
293
+ padding: 10px; /* 押しづらいのでpaddingで押せる領域を広げてやる */
294
+ border: 1px solid black;
295
+ cursor: pointer;
296
+ }
297
+
298
+ /* 押せる範囲に入ったら背景色を変えて教えてやると使い勝手が上がる */
299
+ #prev:hover,
300
+ #next:hover {
301
+ background-color: yellow;
302
+ }
303
+
304
+ .heading {
305
+ display: flex;
306
+ }
307
+
308
+ .header {
309
+ font-weight: bold;
310
+ }
311
+
312
+ .btn {
313
+ margin-left: 150px;
314
+ margin-bottom: 20px;
315
+ }
316
+
317
+ table,
318
+ th,
319
+ tr,
320
+ td {
321
+ border-collapse: collapse;
322
+ border: 2px solid #333;
323
+ }
324
+
325
+ td {
326
+ width: 53px;
327
+ height: 28px;
328
+ text-align: center;
329
+ }
330
330
 
331
- #run {
331
+ td:not([id^="phValue"]):hover { /* 要素を選択ホバーしていることを明示して日付の押し間違いを防ぐ */
332
- cursor: pointer;
332
+ background-color: yellow;
333
- }
333
+ }
334
334
 
335
+ #run {
336
+ cursor: pointer;
337
+ }
338
+
335
- #run:hover {
339
+ #run:hover {
336
- opacity: 0.5;
340
+ opacity: 0.5;
337
- }
341
+ }
338
-
342
+
339
- tbody tr td {
343
+ tbody tr td {
340
- cursor: pointer;
344
+ cursor: pointer;
341
- user-select: none;
345
+ user-select: none;
342
- }
346
+ }
343
-
344
347
  ```
345
348
 
346
349
  以上です。動作確認済みですが、問題があればコメントをつけて下さい。出来る限り対応します。

3

説明の追記

2020/10/10 00:06

投稿

nekora
nekora

スコア501

answer CHANGED
@@ -343,4 +343,7 @@
343
343
 
344
344
  ```
345
345
 
346
- 以上です。動作確認済みですが、問題があればコメントをつけて下さい。出来る限り対応します。
346
+ 以上です。動作確認済みですが、問題があればコメントをつけて下さい。出来る限り対応します。
347
+
348
+ **コードブロックは右上のアイコンをクリックすれば全コピー出来ます。
349
+ コピーして利用してください。**

2

CSSが開示されたので動作する物が完成したので記述差し替え

2020/10/09 12:12

投稿

nekora
nekora

スコア501

answer CHANGED
@@ -1,16 +1,21 @@
1
- ### CSSが提示されていないため、正しく動いているのか判断に迷います。CSSを提示ください
1
+ ~~### CSSが提示されていないため、正しく動いているのか判断に迷います。CSSを提示ください~~
2
+ ### CSSが開示されたので動作確認をし、不具合やUIの利便性などを修正してあります。
2
3
 
3
- kuma_kuma様が修正されたスクリプトを使用しています。
4
+ kuma_kuma様が修正された**スクリプトを加筆修正**して使用しています。
4
5
 
5
6
  HTMLにミスがいくつもあり、具体的には```</tr>```が必要なところに無い所がたくさんありましたので修正してあります。
6
7
 
7
8
  あとkuma_kumaさまが```init()```関数を定義してくださっているので、ページのロードのタイミングで実行するようにしてあります。
8
- 結果、カレンダーは正常に前・後ろに移動しても正しいカレンダーに更新されるようになりましたが
9
- 繰り返しますがCSSを提示ください本当に正しいのかどうか判断できません。
9
+  **追記:なので用途不明なRUNボタンはコメントアウトています。**
10
10
 
11
- とりあえず修正したHTMLとkuma_kuma様修正くださったスクリプトを載せておきま
11
+ 結果、カレンダーは常に前・後ろに移動ても正しいカレンダーに更新されるようになりまし~~繰り返ますがCSSを提示ください。本当に正しいのかどうか判断できません~~
12
- CSSが開示されたら、再度動作確認をして必要なら修正します。
13
12
 
13
+ ~~とりあえず修正したHTMLとkuma_kuma様が修正してくださったスクリプトを載せておきます。~~
14
+ ~~CSSが開示されたら、再度動作確認をして必要なら修正します。~~
15
+
16
+ ### CSSが開示されたので動作確認をし、不具合やUIの利便性などを修正してあります。
17
+ ### 以下が修正した、完全動作版のソースコードです。
18
+
14
19
  ```html
15
20
  <!DOCTYPE html>
16
21
  <html lang="ja">
@@ -26,7 +31,7 @@
26
31
  <h3 id="title" class="thisMonth"></h3>
27
32
  <span id="next">&raquo;</span>
28
33
  </div>
29
- <button id="run" class="btn">RUN</button>
34
+ <!--<button id="run" class="btn">RUN</button> onloadでinit()を呼んでいるので用途不明なrunボタンは不要。コメントアウト-->
30
35
  <div class="container" id="_container">
31
36
  <table class="table1">
32
37
  <thead>
@@ -101,7 +106,6 @@
101
106
  <script src="js/main.js"></script>
102
107
  </body>
103
108
  </html>
104
-
105
109
  ```
106
110
 
107
111
  js/main.js
@@ -111,15 +115,14 @@
111
115
  let month = date.getMonth();
112
116
 
113
117
  function clearCalender() { //前のカレンダーを削除
114
- /* 削除
115
- const table = document.querySelector('.table1');
116
- while (table.firstChild) {
117
- table.removeChild(table.firstChild);
118
+ //と共に<td>追加前に存在していた要素を追加復元
118
- }
119
- */
120
119
  document.getElementById("calender").innerHTML = '';
120
+ document.getElementById("calender").innerHTML ='<th rowspan="2">root</th><th rowspan="2">name</th>';
121
+
121
122
  document.getElementById("week").innerHTML = '';
123
+
122
124
  document.getElementById("tbody1").innerHTML = '';
125
+ document.getElementById("tbody1").innerHTML = '<tr id="row0"><th>2009</th><th>yu-ki</th></tr><tr id="row1"><th>2010</th><th>aya</th></tr><tr id="row2"><th>2011</th><th>rino</th></tr><tr id="row3"><th>2012</th><th>den</th></tr><tr id="row4"><th>2014</th><th>petie</th></tr><tr id="row5"><th>STR</th><th>tanaka</th></tr><tr id="row6"><th>STR</th><th>yoshida</th></tr>';
123
126
  }
124
127
 
125
128
  function renderTitle() {//年月を表示
@@ -181,11 +184,11 @@
181
184
  let phCount = 0;
182
185
  // console.log(td);
183
186
  td.forEach(function(item){
184
- item.addEventListener('click', () => {
187
+ item.addEventListener('click', () => { //tdはquerySelectorAllで複数個になっててforEachで要素1こをitemとして
185
- if (td.textContent==='○') {
188
+ if (item.textContent==='○') { //もらっているのでif文はitem.textContentを見ないといけない
186
189
  phCount--;
187
190
  phValue.textContent = phCount;
188
- } else if (td.textContent==='休') {
191
+ } else if (item.textContent==='休') {
189
192
  phCount++;
190
193
  phValue.textContent = phCount;
191
194
  };
@@ -193,6 +196,23 @@
193
196
  });
194
197
  }
195
198
 
199
+ function resetPh() { // これが無いと月が替わったとき休みの数がどこかクリックするまで、前の値で残るバグがでる
200
+ let phValue = document.getElementById('phValue0');
201
+ phValue.textContent = 0;
202
+ phValue = document.getElementById('phValue1');
203
+ phValue.textContent = 0;
204
+ phValue = document.getElementById('phValue2');
205
+ phValue.textContent = 0;
206
+ phValue = document.getElementById('phValue3');
207
+ phValue.textContent = 0;
208
+ phValue = document.getElementById('phValue4');
209
+ phValue.textContent = 0;
210
+ phValue = document.getElementById('phValue5');
211
+ phValue.textContent = 0;
212
+ phValue = document.getElementById('phValue6');
213
+ phValue.textContent = 0;
214
+ }
215
+
196
216
  function bundling() {
197
217
  clearCalender();
198
218
  renderTitle();
@@ -205,6 +225,7 @@
205
225
  addCell('row4');
206
226
  addCell('row5');
207
227
  addCell('row6');
228
+ resetPh();
208
229
  ph('row0', 'phValue0');
209
230
  ph('row1', 'phValue1');
210
231
  ph('row2', 'phValue2');
@@ -235,4 +256,91 @@
235
256
  });
236
257
  bundling();
237
258
  }
238
- ```
259
+ ```
260
+
261
+ css/styles.css
262
+ ```css
263
+ body {
264
+ margin: 0;
265
+ }
266
+
267
+ .container {
268
+ display: flex;
269
+ justify-content: center;
270
+ }
271
+
272
+ .table1 {
273
+ width: 80%;
274
+ }
275
+
276
+ .thisMonth {
277
+ text-align: center;
278
+ margin: 40px auto;
279
+ }
280
+
281
+ .sat {
282
+ background-color: skyblue;
283
+ }
284
+
285
+ .sun {
286
+ background-color: tomato;
287
+ }
288
+
289
+ #prev,
290
+ #next {
291
+ display: block;
292
+ margin: auto;
293
+ padding: 10px; /* 押しづらいのでpaddingで押せる領域を広げてやる */
294
+ border: 1px solid black;
295
+ cursor: pointer;
296
+ }
297
+
298
+ /* 押せる範囲に入ったら背景色を変えて教えてやると使い勝手が上がる */
299
+ #prev:hover,
300
+ #next:hover {
301
+ background-color: yellow;
302
+ }
303
+
304
+ .heading {
305
+ display: flex;
306
+ }
307
+
308
+ .header {
309
+ font-weight: bold;
310
+ }
311
+
312
+ .btn {
313
+ margin-left: 150px;
314
+ margin-bottom: 20px;
315
+ }
316
+
317
+ table,
318
+ th,
319
+ tr,
320
+ td {
321
+ border-collapse: collapse;
322
+ border: 2px solid #333;
323
+ }
324
+
325
+ td {
326
+ width: 53px;
327
+ height: 28px;
328
+ text-align: center;
329
+ }
330
+
331
+ #run {
332
+ cursor: pointer;
333
+ }
334
+
335
+ #run:hover {
336
+ opacity: 0.5;
337
+ }
338
+
339
+ tbody tr td {
340
+ cursor: pointer;
341
+ user-select: none;
342
+ }
343
+
344
+ ```
345
+
346
+ 以上です。動作確認済みですが、問題があればコメントをつけて下さい。出来る限り対応します。

1

タイプミスの修正

2020/10/09 11:54

投稿

nekora
nekora

スコア501

answer CHANGED
@@ -104,7 +104,7 @@
104
104
 
105
105
  ```
106
106
 
107
- js/main,js
107
+ js/main.js
108
108
  ```javascript
109
109
  const date = new Date();
110
110
  let year = date.getFullYear();