質問編集履歴

1

ソースコードを大幅に書き換えたため、差し替えをさせていただきました。

2021/06/16 07:29

投稿

moe_ko
moe_ko

スコア5

test CHANGED
File without changes
test CHANGED
@@ -16,308 +16,244 @@
16
16
 
17
17
  ```JavaScript
18
18
 
19
- <script language="JavaScript" type="text/javascript">
20
-
21
- const weeks = ['日', '月', '火', '水', '木', '金', '土']
22
-
23
- const date = new Date()
24
-
25
- const year = date.getFullYear()
26
-
27
- const month = date.getMonth() + 1
28
-
29
- const startDate = new Date(year, month - 1, 1) // 月の最初の日を取得
30
-
31
- const endDate = new Date(year, month, 0) // 月の最後の日を取得
32
-
33
- const endDayCount = endDate.getDate() // 月の末日
34
-
35
- const startDay = startDate.getDay() // 月の最初の日の曜日を取得
36
-
37
- let dayCount = 1 // 日にちのカウント
38
-
39
- let weekCount = startDay // 曜日のカウント
40
-
41
- let calendarHtml = '' // HTMLを組み立てる変数
19
+ $(function() {
20
+
21
+ var date = new Date();
22
+
23
+ var year = date.getFullYear();
24
+
25
+ var weekday = [ "日", "月", "火", "水", "木", "金", "土" ];
26
+
27
+
28
+
29
+ // 選択された年月日を取得
30
+
31
+ var selected_year = document.getElementById("id_year");
32
+
33
+ var selected_month = document.getElementById("id_month");
34
+
35
+ let selected_dayCount = 1; // 日にちカウント
36
+
37
+ let calendarHtml = ''; // HTMLを組み立てる変数
38
+
39
+
40
+
41
+ // プルダウン
42
+
43
+ $(function() {
44
+
45
+ /*ループ処理*/
46
+
47
+ optionLoop = function(start, end, id) {
48
+
49
+ var i, opt;
50
+
51
+ opt = null;
52
+
53
+ for (i = end; i >= start ; i--) {
54
+
55
+ if (i === date) {
56
+
57
+ opt += "<option value='" + i + "' selected>" + i + "</option>";
58
+
59
+ } else {
60
+
61
+ opt += "<option value='" + i + "'>" + i + "</option>";
62
+
63
+ }
64
+
65
+ }
66
+
67
+ return document.getElementById(id).innerHTML = opt;
68
+
69
+ };
70
+
71
+
72
+
73
+ /*関数設定*/
74
+
75
+ optionLoop(1990, year, 'id_year');
76
+
77
+ optionLoop(1, 12, 'id_month');
78
+
79
+ });
80
+
81
+
82
+
83
+
84
+
85
+ // カレンダー
86
+
87
+ calendarHtml += '<table>';
88
+
89
+
90
+
91
+ // 見出し
92
+
93
+ calendarHtml += '<tr>'+'<th>'+"日"+'</th>'
94
+
95
+ +'<th>'+"曜日"+'</th>'
96
+
97
+ +'<th>'+"開始"+'</th>'
98
+
99
+ +'<th>'+"終了"+'</th>'
100
+
101
+ +'<th>'+"休憩(h)"+'</th>'
102
+
103
+ +'<th>'+"勤務時間(h)"+'</th>'
104
+
105
+ +'<th>'+"出欠"+'</th>'
106
+
107
+ +'</tr>';
108
+
109
+
110
+
111
+ // 日付
112
+
113
+ $('#id_year,#id_month').change(function() {
114
+
115
+
116
+
117
+ selected_year = $('#id_year').val();
118
+
119
+ selected_month = $('#id_month').val();
120
+
121
+
122
+
123
+ //選択月初日
124
+
125
+ var selected_startDate = new Date( selected_year, selected_month - 1, 1);
126
+
127
+ //月の最後の日
128
+
129
+ var selected_endDate = new Date(selected_year, selected_month, 0);
130
+
131
+ // 月の末日
132
+
133
+ var selected_endDayCount = selected_endDate.getDate();
134
+
135
+ // 月の最初の日の曜日を取得
136
+
137
+ var selected_startDay = selected_startDate.getDay();
138
+
139
+ let selected_weekCount = selected_startDay; // 曜日のカウント
140
+
141
+
142
+
143
+ for (let i = 0; i < selected_endDayCount; ++i) {
144
+
145
+ // 日付の生成
146
+
147
+ calendarHtml += '<tr>'+ '<td>' + selected_dayCount + '</td>';
148
+
149
+ selected_dayCount++;
150
+
151
+ // 曜日の生成
152
+
153
+ calendarHtml += '<td>' + weekday[selected_weekCount] + '</td>'+ '</tr>';
154
+
155
+ if(selected_weekCount >= 6) {
156
+
157
+ selected_weekCount = 0;
158
+
159
+ } else {
160
+
161
+ selected_weekCount++;
162
+
163
+ }
164
+
165
+ }
166
+
167
+ })
168
+
169
+ calendarHtml += '</table>';
170
+
171
+ document.querySelector('#calendar').innerHTML = calendarHtml;
172
+
173
+ });
174
+
175
+ ```
176
+
177
+ ```HTML
178
+
179
+ <h1>勤怠一覧</h1>
180
+
181
+
182
+
183
+ </div>
184
+
185
+ <div class="select">
186
+
187
+
188
+
189
+ <select class="cl_year" id="id_year">
190
+
191
+ </select>
192
+
193
+ <a href="#" class="moji">
194
+
195
+
196
+
197
+ </a>
198
+
199
+ <select class="cl_month" id="id_month" name="name_month">
200
+
201
+ </select>
202
+
203
+ <a href="#" class="moji">
204
+
205
+
206
+
207
+ </a>
208
+
209
+
210
+
211
+ <a href="#" class="hyoji">表示</a>
212
+
213
+
214
+
215
+ <table class="tableAll">
216
+
217
+ <tr>
218
+
219
+ <th>実労働時間(h)</th>
220
+
221
+ <td>h</td>
222
+
223
+ <th>残業時間(h)</th>
224
+
225
+ <td>h</td>
226
+
227
+ <th>休憩時間(h)</th>
228
+
229
+ <td>h</td>
230
+
231
+ </tr>
232
+
233
+ </table>
234
+
235
+ </a>
42
236
 
43
237
 
44
238
 
45
- // 初期表示
46
-
47
- window.onload = function () {
48
-
49
- showProcess(date);
50
-
51
- };
52
-
53
- const config = {
54
-
55
- show: 1,
56
-
57
- }
58
-
59
-
60
-
61
- // 見出し
62
-
63
-
64
-
65
- function showProcess(date) {
66
-
67
- document.querySelector('#header').innerHTML =month + "月 勤怠一覧";
68
-
69
-
70
-
71
- }
72
-
73
-
74
-
75
- // プルダウン
76
-
77
- (function() {
78
-
79
- /*ループ処理*/
80
-
81
- optionLoop = function(start, end, id) {
82
-
83
- var i, opt;
84
-
85
- opt = null;
86
-
87
- for (i = start; i <= end ; i++) {
88
-
89
- if (i === date) {
90
-
91
- opt += "<option value='" + i + "' selected>" + i + "</option>";
92
-
93
- } else {
94
-
95
- opt += "<option value='" + i + "'>" + i + "</option>";
96
-
97
- }
98
-
99
- }
100
-
101
- return document.getElementById(id).innerHTML = opt;
102
-
103
- };
104
-
105
-
106
-
107
- /*関数設定*/
108
-
109
- optionLoop(2010, year, 'id_year');
110
-
111
- optionLoop(1, 12, 'id_month');
112
-
113
- })();
114
-
115
-
116
-
117
-
118
-
119
- // カレンダー
120
-
121
- calendarHtml += '<table>'
122
-
123
-
124
-
125
- // 見出し
126
-
127
- calendarHtml += '<tr>'+'<th>'+"日"+'</th>'
128
-
129
- +'<th>'+"曜日"+'</th>'
130
-
131
- +'<th>'+"開始"+'</th>'
132
-
133
- +'<th>'+"終了"+'</th>'
134
-
135
- +'<th>'+"休憩(h)"+'</th>'
136
-
137
- +'<th>'+"勤務時間(h)"+'</th>'
138
-
139
- +'<th>'+"出欠"+'</th>'
140
-
141
- +'</tr>'
142
-
143
-
144
-
145
- var weekday = [ "日", "月", "火", "水", "木", "金", "土" ];
146
-
147
- {
148
-
149
- for (let i = 0; i < endDayCount; ++i) {
150
-
151
- // 日付の生成
152
-
153
- calendarHtml += '<tr>'+ '<td>' + dayCount + '</td>'
154
-
155
- dayCount++
156
-
157
- // 曜日の生成
158
-
159
- calendarHtml += '<td>' + weekday[weekCount] + '</td>'+ '</tr>'
160
-
161
- if(weekCount >= 6) {
162
-
163
- weekCount = 0;
164
-
165
- } else {
166
-
167
- weekCount++;
168
-
169
- }
170
-
171
- }
172
-
173
- calendarHtml += '</table>'
174
-
175
- document.querySelector('#calendar').innerHTML = calendarHtml
176
-
177
- }
178
-
179
-
180
-
181
- //プルダウンからカレンダーを更新
182
-
183
- $('.calender').each(function() {
184
-
185
- var id = '#' + $(this).attr('id');
186
-
187
- $(id + ' select').bind('change', function() {
188
-
189
- var i = 0;
190
-
191
- var dates = new Array(2);
192
-
193
- $(id + ' select').each(function() {
194
-
195
- dates[i] = $(this).val();
196
-
197
- i++;
198
-
199
- });
200
-
201
- var newdate = dates[0].replace('-','/') + '/' + dates[1];
202
-
203
- $(id + ' input').val(newdate);
204
-
205
- });
206
-
207
- });
208
-
209
-
210
-
211
- </script>
239
+ <a href="#" class="logout">ログアウト</a>
240
+
241
+ </div>
242
+
243
+
244
+
245
+ <table>
246
+
247
+ <div id="calendar"></div>
248
+
249
+ </table>
250
+
251
+
252
+
253
+ <script type="text/javascript" src="itiran.short.js"></script>
212
254
 
213
255
  ```
214
256
 
215
- ```HTML
216
-
217
- <!DOCTYPE html>
218
-
219
- <html lang="ja">
220
-
221
- <head>
222
-
223
- <script src="https://code.jquery.com/jquery-3.3.1.min.js"
224
-
225
- integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
226
-
227
- crossorigin="anonymous"></script>
228
-
229
- <meta charset="utf-8">
230
-
231
- <link rel="stylesheet" href="css/itiran.css">
232
-
233
- <title>勤怠管理システム</title>
234
-
235
- </head>
236
-
237
-
238
-
239
- <body>
240
-
241
- <div class="honbun">
242
-
243
- <div class="top">
244
-
245
- &nbsp;&nbsp;&nbsp;&nbsp;
246
-
247
- <h1 id="header"></h1>
248
-
249
-
250
-
251
- </div>
252
-
253
- <div class="select">
254
-
255
-
256
-
257
- <select class="cl_year" id="id_year">
258
-
259
- </select>
260
-
261
- <a href="#" class="moji">
262
-
263
-
264
-
265
- </a>
266
-
267
- <select class="cl_month" id="id_month">
268
-
269
- </select>
270
-
271
- <a href="#" class="moji">
272
-
273
-
274
-
275
- </a>
276
-
277
-
278
-
279
- <a href="#" class="hyoji">表示</a>
280
-
281
-
282
-
283
- <table class="tableAll">
284
-
285
- <tr>
286
-
287
- <th>実労働時間(h)</th>
288
-
289
- <td>h</td>
290
-
291
- <th>残業時間(h)</th>
292
-
293
- <td>h</td>
294
-
295
- <th>休憩時間(h)</th>
296
-
297
- <td>h</td>
298
-
299
- </tr>
300
-
301
- </table>
302
-
303
- </a>
304
-
305
-
306
-
307
- <a href="#" class="logout">ログアウト</a>
308
-
309
- </div>
310
-
311
-
312
-
313
- <table>
314
-
315
- <div id="calendar"></div>
316
-
317
- </table>
318
-
319
- ```
320
-
321
257
 
322
258
 
323
259
  ### 試したこと