Форум программистов, компьютерный форум, киберфорум
JavaScript для начинающих
Войти
Регистрация
Восстановить пароль
Блоги Сообщество Поиск Заказать работу  
 
 
Рейтинг 4.88/34: Рейтинг темы: голосов - 34, средняя оценка - 4.88
 Аватар для Блондинка йа
13 / 12 / 1
Регистрация: 08.03.2019
Сообщений: 279

Как сделать календарь на год?

18.05.2021, 11:13. Показов 6662. Ответов 37
Метки нет (Все метки)

Студворк — интернет-сервис помощи студентам
есть такой вертикальный календарь,

PHP/HTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
@import url('https://fonts.googleapis.com/css?family=Baumans&display=swap');
body { width: 1100px; }
body, select, input { font: 14px serif; }
#calendar { width: 330px; height: 375px; display: inline-block; border: 1px solid hsl(0,0%,66%); border-radius: 6px/4px; padding: 5px; }
#navigation_panel { background-color: hsl(210, 100%, 92%); min-height: 34px; max-height: 78px; border: 1px solid hsl(0,0%,66%); border-radius: 6px/4px; padding: 10px; margin-bottom: 6px; text-align: center; vertical-align: middle;  display: -webkit-box; display: -webkit-flex; display: flex; -webkit-box-align: center; -webkit-align-items: center; align-items: center; -webkit-box-pack: center; -webkit-justify-content: center; justify-content: center; -webkit-flex-wrap: wrap; flex-wrap: wrap; }
#navigation_panel button, #navigation_panel #calendar_year { background-color: hsl(210, 100%, 85%); color: hsl(210, 100%, 45%); font: 14px serif; border: 1px solid hsl(210, 100%, 45%); }
#calendar_month { background-color: transparent; color: hsl(210,100%,45%); font: 14px serif; border: 1px solid hsl(210, 100%, 45%); }
#navigation_panel button { height: 34px; vertical-align: middle; }
#background_month { background-color: hsl(210, 100%, 85%); display: inline-block; }
button.minus { width: 28px; text-align: center; border-radius: 12px 0 0 12px / 10px 0 0 10px; margin-right: -1px; }
button.plus { width: 28px; text-align: center; border-radius: 0 12px 12px 0 / 0 10px 10px 0; margin-left: -1px; }
.month_plus { margin-right: 35px; }
#presently { width: 234px; margin-top: 10px; border-radius: 12px/10px;}
#calendar_month { width: 89px; display: inline-block; }
#calendar_year { width: 54px; display: inline-block; }
select { height: 34px; }
input { height: 30px; border: 1px solid hsl(0,0%,66%); display: inline-block; text-align: center; }
#table { font-family: 'Baumans', cursive; table-layout: fixed; width: 100%; height: 413px; padding: 2px; }
#table, td { border: 1px solid hsl(0,0%,66%); border-radius: 6px/4px; }
td { margin: 1px; text-align: center; }
#table tbody td.prevMonth { background-color: hsl(210,100%,95%); color: hsl(210,100%,80%); border: 1px solid hsl(0,0%,80%); }
#table tbody tr:nth-child(n + 6) td.prevMonth { background-color: hsl(348,100%,95%); color: hsl(348,100%,80%); border: 1px solid hsl(0,0%,80%); }
.curMonth { background-color: ; }
#table tbody td.nextMonth { background-color: hsl(210,100%,95%); color: hsl(210,100%,80%); border: 1px solid hsl(0,0%,80%); }
#table tbody tr:nth-child(n + 6) td.nextMonth { background-color: hsl(348,100%,95%); color: hsl(348,100%,80%); border: 1px solid hsl(0,0%,80%); }
#presently.hide { display: none; }
#table tbody tr td.week-day { background-color: hsl(210,100%,85%); color: hsl(210,100%,50%); border: 1px solid hsl(0,0%,60%); width: 20%; } /* день недели */
#table tbody tr:nth-child(n + 6) td.week-day { background-color: hsl(348,100%,85%); color: hsl(348,100%,50%); border: 1px solid hsl(0,0%,60%); } /* день недели выходной*/
#table tbody tr td.week-day.curDay { border: 1px solid hsl(210,100%,50%); background-color: hsl(210,100%,75%); color: hsl(210,100%,98%); font-weight: bold; text-shadow: 1px 1px hsl(210,100%,50%), -1px 1px hsl(210,100%,50%), 1px -1px hsl(210,100%,50%), -1px -1px hsl(210,100%,50%), 1px 0 hsl(210,100%,50%), 0 1px hsl(210,100%,50%), -1px 0 hsl(210,100%,50%), 0 -1px hsl(210,100%,50%); letter-spacing: 2px; } /* сегодн день недели */
#table tbody tr:nth-child(n + 6) td.week-day.curDay { border: 1px solid hsl(348,100%,50%); background-color: hsl(348,100%,75%); color: hsl(348,100%,98%); font-weight: bold; text-shadow: 1px 1px hsl(348,100%,50%), 1px -1px hsl(348,100%,50%), -1px 1px hsl(348,100%,50%), -1px -1px hsl(348,100%,50%), 1px 0 hsl(348,100%,50%), -1px 0 hsl(348,100%,50%), 0 1px hsl(348,100%,50%), 0 -1px hsl(348,100%,50%); letter-spacing: 2px; } /* сегодн день недели выходной */
#table tbody td { background-color: hsl(210,100%,90%); color: hsl(210,100%,50%); } /* будние дни текущего месяца */
#table tbody tr:nth-child(n + 6) td{ background-color: hsl(348,100%,90%); color: hsl(348,100%,50%); } /* выходные дни текущего месяца */
#table tbody tr td.curMonth.curDay { background-color: hsl(210,100%,80%); border: 1px solid hsl(210, 100%, 50%); font-weight: bold; color: hsl(210,100%,100%); text-shadow: 1px 1px hsl(210,100%,50%), -1px 1px hsl(210,100%,50%), 1px -1px hsl(210,100%,50%), -1px -1px hsl(210,100%,50%), 1px 0 hsl(210,100%,50%), 0 1px hsl(210,100%,50%), -1px 0 hsl(210,100%,50%), 0 -1px hsl(210,100%,50%); letter-spacing: 3px; } /* сегодня будний */
#table tbody tr:nth-child(n + 6) td.curMonth.curDay { background-color: hsl(348,100%,80%); border: 1px solid hsl(348,100%,50%); color: hsl(348,100%,100%); text-shadow: 1px 1px hsl(348,100%,50%), 1px -1px hsl(348,100%,50%), -1px 1px hsl(348,100%,50%), -1px -1px hsl(348,100%,50%), 1px 0 hsl(348,100%,50%), -1px 0 hsl(348,100%,50%), 0 1px hsl(348,100%,50%), 0 -1px hsl(348,100%,50%); letter-spacing: 3px; } /* сегодня выходной */
 
#calendar { display: flex; flex-direction: column; }
.content_month { flex: 1; }
#table { height:100%; }
 
button, select, input { outline: none; }
 
</style>
</head>
<body>
<div id="calendar">
<div id="navigation_panel">
<button class="month_minus minus"></button>
<span id="background_month"><select id="calendar_month"></select></span>
<button class="month_plus plus"></button>
<button class="year_minus minus"></button>
<input type="number" size="4" id="calendar_year" />
<button class="year_plus plus"></button><br />
<button id="presently">сегодня</button>
</div>
<div class="content_month">
<table id="table">
<tbody></tbody>
</table></div>
</div>
 <script>
Date.prototype.reduce = function(callback, value) {
 var year = this.getFullYear();
 var month = this.getMonth();
 var step = new Date(year, month, 1);
 var last = new Date(year, month + 1, 0);
 step.setHours(24 * (0 - ((step.getDay() + 6) % 7)));
 last.setHours(24 * (6 - ((last.getDay() + 6) % 7)));
 for (var i = 0; step <= last; i++) {
 value = callback(value, new Date(+step), i, this);
 step.setHours(24);
 }
 return value;
};
var data = new Date();
var selectMonth = document.querySelector('#calendar_month');
var monthNames = [
 'Январь',
 'Февраль',
 'Март',
 'Апрель',
 'Май',
 'Июнь',
 'Июль',
 'Август',
 'Сентябрь',
 'Октябрь',
 'Ноябрь',
 'Декабрь',
];
monthNames.forEach(function(monthName, i) {
 selectMonth.options[i] = new Option(monthName, i);
});
selectMonth.addEventListener('change', function() {
 data.setMonth(this.value);
 createCalendar(data);
});
var minusMonth = document.querySelector('.month_minus');
minusMonth.addEventListener('click', function() {
 data.setMonth(data.getMonth() - 1);
 createCalendar(data);
});
var plusMonth = document.querySelector('.month_plus');
plusMonth.addEventListener('click', function() {
 data.setMonth(data.getMonth() + 1);
 createCalendar(data);
});
var minusYear = document.querySelector('.year_minus');
minusYear.addEventListener('click', function() {
 data.setYear(data.getFullYear() - 1);
 createCalendar(data);
});
var plusYear = document.querySelector('.year_plus');
plusYear.addEventListener('click', function() {
 data.setYear(data.getFullYear() + 1);
 createCalendar(data);
});
var inputYear = document.querySelector('#calendar_year');
inputYear.addEventListener('input', function() {
 if (/^d{4}$/.test(this.value)) {
 data.setYear(this.value);
 createCalendar(data);
 }
});
var currentButton = document.querySelector('#presently');
currentButton.addEventListener('click', function() {
 data = new Date();
 createCalendar(data);
});
 
function createCalendar(data) {
 var now = new Date().setHours(0, 0, 0, 0);
 var year = data.getFullYear();
 inputYear.value = year;
 var month = data.getMonth();
 selectMonth.selectedIndex = month;
 currentButton.classList.remove('hide');
 var indexcurDay;
 var cls = ['prevMonth', 'curMonth', 'nextMonth'],
 indexCls = 0;
 var html = data.reduce(function(value, current, index, source) {
 var date = current.getDate();
 if (date == 1) indexCls++;
 var className = cls[indexCls];
 if (+now == +current && indexCls == 1) {
 className += ' curDay';
 currentButton.classList.add('hide');
 indexcurDay = index % 7;
 }
 value[index % 7] += '<td class="' + className + '">' + date;
 return value
 }, ['<tr><td class="week-day">Пн.',
             '<tr><td class="week-day">Вт.',
             '<tr><td class="week-day">Ср.',
             '<tr><td class="week-day">Чт.',
             '<tr><td class="week-day">Пт.',
             '<tr><td class="week-day">Сб.',
             '<tr><td class="week-day">Вс.']);
 document.querySelector('#table tbody').innerHTML = html.join('');
 var daysTd = document.querySelectorAll('.week-day');
 if(indexcurDay !== void 0) daysTd[indexcurDay].classList.add('curDay');
}
createCalendar(data);
var timer;
function refresh() {
 window.clearTimeout(timer);
 var finish = new Date().setHours(24, 0, 0, 0);
 finish -= data;
 timer = window.setTimeout(function() {
 createCalendar(data);
 refresh();
 }, finish);
}
refresh();
 </script>
 </body>
</html>
возможно ли в него добавить ссылку, при клике на которую, html-код страницы станет таким

HTML5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<style type="text/css">
 #calendar_Year { width: 996px; padding: 5px; border: 1px solid hsl(0,0%,66%); }
 #navigation_panel_year { width: 954px; border: 1px solid hsl(0,0%,66%); white-space: nowrap; padding: 10px 20px; margin: 0 0 3px 0; }
 #table_year { width: 1020px; border: none; margin: 0 0 0 -2px;; padding: 0; }
 .td_month { width: 330px; height: 375px; border: 1px solid hsl(0,0%,66%); border-radius: 0px/0px; padding: 5px; margin-left: -2px; }
 div.month_name { border: 1px solid hsl(0,0%,66%); padding: 10px 0;}
 button.year_minus { background-color: hsl(210, 100%, 85%); width: 28px; height: 34px; text-align: center; border-radius: 12px 0 0 12px / 10px 0 0 10px; margin-right: -6px; }
 button.year_plus { background-color: hsl(210, 100%, 85%); width: 28px; height: 34px; text-align: center; border-radius: 0 12px 12px 0 / 0 10px 10px 0; margin-left: -6px; }
 .month_plus { margin-right: 35px; }
 #presently { width: 234px; margin-top: 10px; border-radius: 12px/10px;}
 #calendar_month { width: 89px; display: inline-block; }
 #calendar_year { width: 54px; display: inline-block; }
 select { height: 34px; }
 #calendar_year { height: 30px; display: inline-block; text-align: center;  }
 button.year_minus, button.year_plus, #calendar_year { background-color: hsl(210,100%,85%); color: hsl(210,100%,45%); font: 14px serif; border: 1px solid hsl(210,100%,45%); }
 </style>
 <div id="calendar_Year">
 <div id="navigation_panel_year">
 Календарь на <button class="year_minus"></button>
 <input type="number" size="4" id="calendar_year"/>
 <button class="year_plus">+</button> год. <br/>
 <button id="presently_year" style="display: none;">сегодня</button>
 </div>
 <div class="content_year">
 <table id="table_year">
 <tr><td class="td_month"><div class="month_name"></div></td><td class="td_month"><div class="month_name"></div></td><td class="td_month"><div class="month_name"></div></td></tr>
 <tr><td class="td_month"><div class="month_name"></div></td><td class="td_month"><div class="month_name"></div></td><td class="td_month"><div class="month_name"></div></td></tr>
 <tr><td class="td_month"><div class="month_name"></div></td><td class="td_month"><div class="month_name"></div></td><td class="td_month"><div class="month_name"></div></td></tr>
 <tr><td class="td_month"><div class="month_name"></div></td><td class="td_month"><div class="month_name"></div></td><td class="td_month"><div class="month_name"></div></td></tr>
 </table></div>
<a>календарь на месяц</a>
и отобразится календарь на год, а при клике на ссылку "календарь на месяц опять вернулся к отображению месяца?

другими словами, при клике на ссылку "календарь на год" пропадёт выпадающий список для выбора месяца, с кнопками - и + месяц, а вместо списка появится текст "календарь на <button>-</button><input/><button>+</button> год."
0
cpp_developer
Эксперт
20123 / 5690 / 1417
Регистрация: 09.04.2010
Сообщений: 22,546
Блог
18.05.2021, 11:13
Ответы с готовыми решениями:

Библиотека GGI. Программа рисует календарь на указанный год (год задаётся параметром командной строки)
Реализовать программу с использованием библиотеки GGI. Программа рисует календарь на указанный год (год задаётся параметром командной...

Как вывести календарь на год в Oracle SQL?
Результат должен быть таким: пн вт ср чт пт сб вс Январь 2013 __ 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21...

Как вывести календарь на год в Oracle SQL?
Оформление должно быть таким: пн вт ср чт пт сб вс Январь 2013 __ 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 ...

37
 Аватар для Блондинка йа
13 / 12 / 1
Регистрация: 08.03.2019
Сообщений: 279
27.05.2021, 23:53  [ТС]
Студворк — интернет-сервис помощи студентам
S O S

как выделить цветом в календарь сегодн число, сегодн день недели, текущий месяц, дни недели других месяцев, и сделать навигацию по годам?

PHP/HTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8">
        <title></title>
        <style>
          #table_year {
            table-layout: fixed;
            width: 100%;
            border: 1px solid hsl(0, 0%, 66%);
            border-radius: 4px;
          }
 
          .td_month {
            width: 260px;
            height: 270px;
            border: 1px solid hsl(0, 0%, 66%);
            border-radius: 4px;
          }
 
          #num_year,
          #January,
          #February, 
          #March,
          #April, 
          #May,
          #June, 
          #July,
          #August, 
          #September,
          #October, 
          #November,
          #December {
            background-color: hsl(210, 100%, 95%);
            color: hsl(210, 100%, 50%);
            font: bold 18px serif;
            text-align: center;
            border: 1px solid hsl(0,0%,66%);
            border-radius: 4px;
            padding: 5px;
            margin: 0 0 5px 0;
          }
 
          #num_year {
            font: bold 24px serif;
            width: 780px;
            border: 1px solid hsl(0, 0%, 66%);
            border-radius: 4px;
            padding: 5px;
            margin: 0 0 5px 0;
          }
 
          #month1,
          #month2,
          #month3,
          #month4,
          #month5,
          #month6,
          #month7,
          #month8,
          #month9,
          #month10,
          #month11,
          #month12 {
            display: inline-block;
            border: 1px solid hsl(0, 0%, 66%);
            border-radius: 4px;
            padding: 5px;
            width: auto;
          }
 
          .day {
            border: 1px solid hsl(0, 0%, 66%);
            width: auto;
            line-height: 30px;
            text-align: center;
            margin: 1px;
            background-color: hsl(210, 100%, 95%);
            color: hsl(210, 100%, 50%);
          }
 
          .table_month {
            table-layout: fixed;
            width: 100%;
            height: 220px;
            border: 1px solid hsl(0, 0%, 66%);
            border-radius: 4px;
          }
 
          .table_month tr td:nth-child(1) {
          width: 20%;
          font-weight: bold;
          }
          
          .table_month tr td.day:nth-child(1) {
          background-color: hsl(210, 100%, 88%);
          color: hsl(210, 100%, 60%);
          }
          
          .table_month tr:nth-child(n + 6) td.day:nth-child(1) {
          background-color: hsl(348, 100%, 88%);
          color: hsl(348, 100%, 60%);
          }
 
          .table_month tr:nth-child(n + 6) td.day {
            background-color: hsl(348, 100%, 95%);
            color: hsl(348, 100%, 50%);
          }
          
          #year_input {
            border: 1px solid hsl(0,0%,66%);
            display: inline-block;
            text-align: center;
            font: bold 24px serif;
            color: hsl(210,100%,50%);
            width: 100px;
          }
 
        </style>
      </head>
 
      <body>
        <div id="num_year">
        Календарь на 
        <button class="year_minus"></button>
        <input id="year_input" type="number" size="4" value="2021"/> 
        <button class="year_plus"></button>
        год.</button><br/>
    <button id="presently">сегодня</button>
        </div>
        <table id="table_year">
          <tr>
            <td class="td_month">
              <div id="month1">
                <div id="January"></div>
                <table class="table_month"></table>
              </div>
            </td>
            <td class="td_month">
              <div id="month2">
                <div id="February"></div>
                <table class="table_month"></table>
              </div>
            </td>
            <td class="td_month">
              <div id="month3">
                <div id="March"></div>
                <table class="table_month"></table>
              </div>
            </td>
          </tr>
          <tr>
            <td class="td_month">
              <div id="month4">
                <div id="April"></div>
                <table class="table_month"></table>
              </div>
            </td>
            <td class="td_month">
              <div id="month5">
                <div id="May"></div>
                <table class="table_month"></table>
              </div>
            </td>
            <td class="td_month">
              <div id="month6">
                <div id="June"></div>
                <table class="table_month"></table>
              </div>
            </td>
          </tr>
          <tr>
            <td class="td_month">
              <div id="month7">
                <div id="July"></div>
                <table class="table_month"></table>
              </div>
            </td>
            <td class="td_month">
              <div id="month8">
                <div id="August"></div>
                <table class="table_month"></table>
              </div>
            </td>
            <td class="td_month">
              <div id="month9">
                <div id="September"></div>
                <table class="table_month"></table>
              </div>
            </td>
          </tr>
          <tr>
            <td class="td_month">
              <div id="month10">
                <div id="October"></div>
                <table class="table_month"></table>
              </div>
            </td>
            <td class="td_month">
              <div id="month11">
                <div id="November"></div>
                <table class="table_month"></table>
              </div>
            </td>
            <td class="td_month">
              <div id="month12">
                <div id="December"></div>
                <table class="table_month"></table>
              </div>
            </td>
          </tr>
        </table>
        <script>
          var calendar = {
            update: function(year, month) {
              this.year = year;
              this.month = ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'][month];
              var startDay = new Date(year, month, 1);
              var offsetDay = (startDay.getDay() || 7) - 1;
              startDay.setDate(startDay.getDate() - offsetDay);
              var lastDay = new Date(startDay);
              var days = new Date(year, month + 1, 0).getDate();
              days = Math.ceil((days + offsetDay) / 7) * 7;
              lastDay.setDate(lastDay.getDate() + days);
              this.data = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
              while (startDay < lastDay) {
                this.data.push(startDay.getDate());
                startDay.setHours(24);
              }
            },
            render: function() {
              var html = ['<tr class="week_day">', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>'];
              for (var i = 0; i < this.data.length; i++) {
                html[i % 7] += '<td class="day">' + this.data[i];
              }
              this.monthName.textContent = this.month;
              this.element.innerHTML = html.join('');
            },
          };
          var today = new Date(),
            thisYear = today.getFullYear(),
            thisMonth = today.getMonth(),
            months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
            
          calendar.days = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
          calendar.numYear = document.querySelector('#num_year');
          
          months.forEach((v,i) => {
            calendar.monthName = document.querySelector(`#${v}`);
            calendar.element = document.querySelectorAll('.table_month')[i];
            calendar.update(thisYear, i);
            calendar.render();
          });
        </script>
      </body>
    </html>
как в этом скрипте

PHP/HTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<!DOCTYPE html>
    <html lang="ru">
    <head>
    <meta charset="utf-8">
    <title>Вертикальный календарь</title>
    <style type="text/css">
    @import url('https://fonts.googleapis.com/css?family=Baumans&display=swap');
    body { width: 1023px; }
    body, select, input { font: 14px serif; }
    #calendar { width: 330px; height: 375px; display: inline-block; border: 1px solid hsl(0,0%,66%); border-radius: 6px/4px; padding: 5px; margin: 0 0 5px 0; }
    #navigation_panel {
    background-color: hsl(210,100%,92%);
    min-height: 34px; 
    max-height: 78px;
    border: 1px solid hsl(0,0%,66%);
    border-radius: 6px/4px;
    padding: 10px;
    margin-bottom: 5px;
    text-align: center;
    vertical-align: middle; 
    display: -webkit-box; 
    display: -webkit-flex; 
    display: flex;
    -webkit-box-align: center; 
    -webkit-align-items: center; 
    align-items: center; 
    -webkit-box-pack: center; 
    -webkit-justify-content: center; 
    justify-content: center; 
    -webkit-flex-wrap: wrap;
    flex-wrap: wrap; }
    #navigation_panel button,
    #navigation_panel #calendar_year {
    background-color: hsl(210,100%,85%);
    color: hsl(210,100%,45%);
    font: 14px serif;
    border: 1px solid hsl(210,100%,45%); }
    #calendar_month {
    background-color: transparent;
    color: hsl(210,100%,45%);
    font: 14px serif;
    border: 1px solid hsl(210,100%,45%); }
    #navigation_panel button { 
    height: 34px;
    vertical-align: middle; }
    #background_month {
    background-color: hsl(210,100%,85%);
    display: inline-block; }
    button.minus { 
    width: 28px;
    text-align: center;
    border-radius: 12px 0 0 12px / 10px 0 0 10px;
    margin-right: -1px; }
    button.plus {
    width: 28px;
    text-align: center;
    border-radius: 0 12px 12px 0 / 0 10px 10px 0;
    margin-left: -1px; }
    .month_plus {
    margin-right: 35px; }
    .arrow {
    display: inline-block;
    line-height: 0.5; }
    #presently {
    width: 234px;
    margin-top: 10px;
    border-radius: 12px/10px; }
    #calendar_month {
    width: 89px;
    display: inline-block; }
    #calendar_year {
    width: 54px;
    display: inline-block; }
    select {
    height: 34px; }
    input {
    height: 30px;
    display: inline-block;
    text-align: center; }
    #table {
    font-family: 'Baumans', cursive;
    table-layout: fixed;
    width: 100%;
    height: 413px;
    padding: 2px; }
    #table, td {
    border: 1px solid hsl(0,0%,66%);
    border-radius: 6px/4px; }
    td {
    margin: 1px;
    text-align: center; }
    #table tbody td.prevMonth {
    background-color: hsl(210,100%,95%);
    color: hsl(210,100%,80%);
    border: 1px solid hsl(0,0%,80%); } /* будние дни предыдущего месяца */
    #table tbody tr:nth-child(n + 6) td.prevMonth {
    background-color: hsl(348,100%,95%);
    color: hsl(348,100%,80%);
    border: 1px solid hsl(0,0%,80%); } /* выходные дни предыдущего месяца */
    #table tbody td.nextMonth {
    background-color: hsl(210,100%,95%);
    color: hsl(210,100%,80%);
    border: 1px solid hsl(0,0%,80%); } /* будние дни следующего месяца */
    #table tbody tr:nth-child(n + 6) td.nextMonth {
    background-color: hsl(348,100%,95%);
    color: hsl(348,100%,80%);
    border: 1px solid hsl(0,0%,80%); } /* выходные дни следующего месяца */
    #presently.hide {
    display: none; }
    #table tbody tr td.week-day {
    background-color: hsl(210,100%,85%);
    color: hsl(210,100%,50%);
    border: 1px solid hsl(0,0%,60%);
    width: 20%; } /* день недели */
    #table tbody tr:nth-child(n + 6) td.week-day {
    background-color: hsl(348,100%,85%);
    color: hsl(348,100%,50%);
    border: 1px solid hsl(0,0%,60%); } /* день недели выходной*/
    #table tbody tr td.week-day.curDay {
    border: 1px solid hsl(210,100%,50%);
    background-color: hsl(210,100%,75%);
    color: hsl(210,100%,98%);
    font-weight: bold;
    text-shadow:
    1px 1px hsl(210,100%,50%),
    -1px 1px hsl(210,100%,50%),
    1px -1px hsl(210,100%,50%),
    -1px -1px hsl(210,100%,50%),
    1px 0 hsl(210,100%,50%),
    0 1px hsl(210,100%,50%),
    -1px 0 hsl(210,100%,50%),
    0 -1px hsl(210,100%,50%);
    letter-spacing: 2px; } /* сегодн день недели */
    #table tbody tr:nth-child(n + 6) td.week-day.curDay { border: 1px solid hsl(348,100%,50%); background-color: hsl(348,100%,75%); color: hsl(348,100%,98%); font-weight: bold; text-shadow: 1px 1px hsl(348,100%,50%), 1px -1px hsl(348,100%,50%), -1px 1px hsl(348,100%,50%), -1px -1px hsl(348,100%,50%), 1px 0 hsl(348,100%,50%), -1px 0 hsl(348,100%,50%), 0 1px hsl(348,100%,50%), 0 -1px hsl(348,100%,50%); letter-spacing: 2px; } /* сегодн день недели выходной */
    #table tbody td {
    background-color: hsl(210,100%,90%);
    color: hsl(210,100%,50%); } /* будние дни текущего месяца */
    #table tbody tr:nth-child(n + 6) td{ background-color: hsl(348,100%,90%); color: hsl(348,100%,50%); } /* выходные дни текущего месяца */
    #table tbody tr td.curMonth.curDay { background-color: hsl(210,100%,80%); border: 1px solid hsl(210,100%,50%); font-weight: bold; color: hsl(210,100%,100%); text-shadow: 1px 1px hsl(210,100%,50%), -1px 1px hsl(210,100%,50%), 1px -1px hsl(210,100%,50%), -1px -1px hsl(210,100%,50%), 1px 0 hsl(210,100%,50%), 0 1px hsl(210,100%,50%), -1px 0 hsl(210,100%,50%), 0 -1px hsl(210,100%,50%); letter-spacing: 3px; } /* сегодня будний */
    #table tbody tr:nth-child(n + 6) td.curMonth.curDay { background-color: hsl(348,100%,80%); border: 1px solid hsl(348,100%,50%); color: hsl(348,100%,100%); text-shadow: 1px 1px hsl(348,100%,50%), 1px -1px hsl(348,100%,50%), -1px 1px hsl(348,100%,50%), -1px -1px hsl(348,100%,50%), 1px 0 hsl(348,100%,50%), -1px 0 hsl(348,100%,50%), 0 1px hsl(348,100%,50%), 0 -1px hsl(348,100%,50%); letter-spacing: 3px; } /* сегодня выходной */
    
    #calendar { display: flex; flex-direction: column; }
    .content_month { flex: 1; }
    #table { height:100%; }
    
    button, select, input { outline: none; }
    
     </style>
    </head>
    <body>
    <div id="calendar">
    <div id="navigation_panel">
    <button class="month_minus minus"><span class="arrow"></span></button>
    <span id="background_month"><select id="calendar_month"></select></span>
    <button class="month_plus plus"><span class="arrow"></span></button>
    <button class="year_minus minus"><span class="arrow"></span></button>
    <input type="number" size="4" id="calendar_year"/>
    <button class="year_plus plus"><span class="arrow"></span></button><br/>
    <button id="presently">сегодня</button>
    </div>
    <div class="content_month">
    <table id="table">
    <tbody></tbody>
    </table></div>
    </div>
     <script>
    Date.prototype.reduce = function(callback, value) {
     var year = this.getFullYear();
     var month = this.getMonth();
     var step = new Date(year, month, 1);
     var last = new Date(year, month + 1, 0);
     step.setHours(24 * (0 - ((step.getDay() + 6) % 7)));
     last.setHours(24 * (6 - ((last.getDay() + 6) % 7)));
     for (var i = 0; step <= last; i++) {
     value = callback(value, new Date(+step), i, this);
     step.setHours(24);
     }
     return value;
    };
    var data = new Date();
    var selectMonth = document.querySelector('#calendar_month');
    var monthNames = [ 'Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь',];
    monthNames.forEach(function(monthName, i) {
     selectMonth.options[i] = new Option(monthName, i);
    });
    selectMonth.addEventListener('change', function() {
     data.setMonth(this.value);
     createCalendar(data);
    });
    var minusMonth = document.querySelector('.month_minus');
    minusMonth.addEventListener('click', function() {
     data.setMonth(data.getMonth() - 1);
     createCalendar(data);
    });
    var plusMonth = document.querySelector('.month_plus');
    plusMonth.addEventListener('click', function() {
     data.setMonth(data.getMonth() + 1);
     createCalendar(data);
    });
    var minusYear = document.querySelector('.year_minus');
    minusYear.addEventListener('click', function() {
     data.setYear(data.getFullYear() - 1);
     createCalendar(data);
    });
    var plusYear = document.querySelector('.year_plus');
    plusYear.addEventListener('click', function() {
     data.setYear(data.getFullYear() + 1);
     createCalendar(data);
    });
    var inputYear = document.querySelector('#calendar_year');
    inputYear.addEventListener('input', function() {
     if (/^\d{4}$/.test(this.value)) {
     data.setYear(this.value);
     createCalendar(data);
     }
    });
    var currentButton = document.querySelector('#presently');
    currentButton.addEventListener('click', function() {
     data = new Date();
     createCalendar(data);
    });
    
    function createCalendar(data) {
     var now = new Date().setHours(0, 0, 0, 0);
     var year = data.getFullYear();
     inputYear.value = year;
     var month = data.getMonth();
     selectMonth.selectedIndex = month;
     currentButton.classList.remove('hide');
     var indexcurDay;
     var cls = ['prevMonth', 'curMonth', 'nextMonth'],
     indexCls = 0;
     var html = data.reduce(function(value, current, index, source) {
     var date = current.getDate();
     if (date == 1) indexCls++;
     var className = cls[indexCls];
     if (+now == +current && indexCls == 1) {
     className += ' curDay';
     currentButton.classList.add('hide');
     indexcurDay = index % 7;
     }
     value[index % 7] += '<td class="' + className + '">' + date;
     return value
     }, ['<tr><td class="week-day">Пн.',
                 '<tr><td class="week-day">Вт.',
                 '<tr><td class="week-day">Ср.',
                 '<tr><td class="week-day">Чт.',
                 '<tr><td class="week-day">Пт.',
                 '<tr><td class="week-day">Сб.',
                 '<tr><td class="week-day">Вс.']);
     document.querySelector('#table tbody').innerHTML = html.join('');
     var daysTd = document.querySelectorAll('.week-day');
     if(indexcurDay !== void 0) daysTd[indexcurDay].classList.add('curDay');
    }
    createCalendar(data);
    var timer;
    function refresh() {
     window.clearTimeout(timer);
     var finish = new Date().setHours(24, 0, 0, 0);
     finish -= data;
     timer = window.setTimeout(function() {
     createCalendar(data);
     refresh();
     }, finish);
    }
    refresh();
     </script>
     </body>
    </html>

S O S
как сделать? чтобы в глаза сразу бросалось что сегодня такое-то число, день недели, какой сейчас месяц, и чтобы с помощью стилей можно было скрывать/показывать дни других месяцев в таблице за месяц... :-)
0
123 / 98 / 15
Регистрация: 02.02.2014
Сообщений: 346
28.05.2021, 13:26
JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var today   = new Date(),
            thisYear  = today.getFullYear(),
            thisMonth = today.getMonth(),
            thisDay   = today.getDate(),  //new
            months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
            
          calendar.days = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
          calendar.numYear = document.querySelector('#num_year'); 
          months.forEach((v,i) => {
            calendar.monthName = document.querySelector(`#${v}`);
            calendar.element = document.querySelectorAll('.table_month')[i];
            calendar.currentDay = i == thisMonth ? thisDay : false  //new
            calendar.update(thisYear, i);
            calendar.render();
          });

JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
13
    render: function() {
              var html = ['<tr class="week_day">', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>'];
              for (var i = 0; i < this.data.length; i++) {
                let cellClass = '';  
             
                if (this.currentDay && this.currentDay == this.data[i]) { 
                   cellClass = ' currentDay';  // оформление класса в css
                }
                html[i % 7] += '<td class="day' + cellClass + '" >' + this.data[i];
              }
              this.monthName.textContent = this.month;
              this.element.innerHTML = html.join('');
            },
Добавлено через 3 минуты
Ещё год нужно тоже сравнить .
0
 Аватар для Блондинка йа
13 / 12 / 1
Регистрация: 08.03.2019
Сообщений: 279
28.05.2021, 19:39  [ТС]
nikolya223, в календаре, в таблице каждого месяца отображаются даты предыдущего, текущего и будущего месяцев, сегодня 28 мая, вот и получается что в таблице месяца две даты 28 апреля и 28 мая, и они обе поменяли класс...

PHP/HTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8">
        <title></title>
        <style>
          #table_year {
            table-layout: fixed;
            width: 100%;
            border: 1px solid hsl(0, 0%, 66%);
            border-radius: 4px;
          }
 
          .td_month {
            width: 260px;
            height: 270px;
            border: 1px solid hsl(0, 0%, 66%);
            border-radius: 4px;
          }
 
          #num_year,
          #January,
          #February, 
          #March,
          #April, 
          #May,
          #June, 
          #July,
          #August, 
          #September,
          #October, 
          #November,
          #December {
            background-color: hsl(210, 100%, 95%);
            color: hsl(210, 100%, 50%);
            font: bold 18px serif;
            text-align: center;
            border: 1px solid hsl(0,0%,66%);
            border-radius: 4px;
            padding: 5px;
            margin: 0 0 5px 0;
          }
 
          #num_year {
            font: bold 24px serif;
            width: 780px;
            border: 1px solid hsl(0, 0%, 66%);
            border-radius: 4px;
            padding: 5px;
            margin: 0 0 5px 0;
          }
 
          #month1,
          #month2,
          #month3,
          #month4,
          #month5,
          #month6,
          #month7,
          #month8,
          #month9,
          #month10,
          #month11,
          #month12 {
            display: inline-block;
            border: 1px solid hsl(0, 0%, 66%);
            border-radius: 4px;
            padding: 5px;
            width: auto;
          }
 
          .day {
            border: 1px solid hsl(0, 0%, 66%);
            width: auto;
            line-height: 30px;
            text-align: center;
            margin: 1px;
            background-color: hsl(210, 100%, 95%);
            color: hsl(210, 100%, 50%);
          }
          
          .table_month tr td.currentDay {
            background-color: hsl(120, 100%, 95%);
            color: hsl(120, 100%, 50%);
            border: 1px solid hsl(120,100%,50%);
            text-align: center;
          }
 
          .table_month {
            table-layout: fixed;
            width: 100%;
            height: 220px;
            border: 1px solid hsl(0, 0%, 66%);
            border-radius: 4px;
          }
 
          .table_month tr td:nth-child(1) {
          width: 20%;
          font-weight: bold;
          }
          
          .table_month tr td.day:nth-child(1) {
          background-color: hsl(210, 100%, 88%);
          color: hsl(210, 100%, 60%);
          }
          
          .table_month tr:nth-child(n + 6) td.day:nth-child(1) {
          background-color: hsl(348, 100%, 88%);
          color: hsl(348, 100%, 60%);
          }
 
          .table_month tr:nth-child(n + 6) td.day {
            background-color: hsl(348, 100%, 95%);
            color: hsl(348, 100%, 50%);
          }
          
          #year_input {
            border: 1px solid hsl(0,0%,66%);
            display: inline-block;
            text-align: center;
            font: bold 24px serif;
            color: hsl(210,100%,50%);
            width: 100px;
          }
 
        </style>
      </head>
 
      <body>
        <div id="num_year">
        Календарь на 
        <button class="year_minus"></button>
        <input id="year_input" type="number" size="4" value="2021"/> 
        <button class="year_plus"></button>
        год. 
        </div>
        <table id="table_year">
          <tr>
            <td class="td_month">
              <div id="month1">
                <div id="January"></div>
                <table class="table_month"></table>
              </div>
            </td>
            <td class="td_month">
              <div id="month2">
                <div id="February"></div>
                <table class="table_month"></table>
              </div>
            </td>
            <td class="td_month">
              <div id="month3">
                <div id="March"></div>
                <table class="table_month"></table>
              </div>
            </td>
          </tr>
          <tr>
            <td class="td_month">
              <div id="month4">
                <div id="April"></div>
                <table class="table_month"></table>
              </div>
            </td>
            <td class="td_month">
              <div id="month5">
                <div id="May"></div>
                <table class="table_month"></table>
              </div>
            </td>
            <td class="td_month">
              <div id="month6">
                <div id="June"></div>
                <table class="table_month"></table>
              </div>
            </td>
          </tr>
          <tr>
            <td class="td_month">
              <div id="month7">
                <div id="July"></div>
                <table class="table_month"></table>
              </div>
            </td>
            <td class="td_month">
              <div id="month8">
                <div id="August"></div>
                <table class="table_month"></table>
              </div>
            </td>
            <td class="td_month">
              <div id="month9">
                <div id="September"></div>
                <table class="table_month"></table>
              </div>
            </td>
          </tr>
          <tr>
            <td class="td_month">
              <div id="month10">
                <div id="October"></div>
                <table class="table_month"></table>
              </div>
            </td>
            <td class="td_month">
              <div id="month11">
                <div id="November"></div>
                <table class="table_month"></table>
              </div>
            </td>
            <td class="td_month">
              <div id="month12">
                <div id="December"></div>
                <table class="table_month"></table>
              </div>
            </td>
          </tr>
        </table>
        <script>
          var calendar = {
            update: function(year, month) {
              this.year = year;
              this.month = ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'][month];
              var startDay = new Date(year, month, 1);
              var offsetDay = (startDay.getDay() || 7) - 1;
              startDay.setDate(startDay.getDate() - offsetDay);
              var lastDay = new Date(startDay);
              var days = new Date(year, month + 1, 0).getDate();
              days = Math.ceil((days + offsetDay) / 7) * 7;
              lastDay.setDate(lastDay.getDate() + days);
              this.data = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
              while (startDay < lastDay) {
                this.data.push(startDay.getDate());
                startDay.setHours(24);
              }
            },
            render: function() {
            var html = ['<tr class="week_day">', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>'];
            for (var i = 0; i < this.data.length; i++) {
            var cellClass = '';  
            
            if (this.currentDay && this.currentDay == this.data[i]) { 
            cellClass = ' currentDay ';  // оформление класса в css
            }
            html[i % 7] += '<td class="day' + cellClass + '" >' + this.data[i];
            }
            this.monthName.textContent = this.month;
            this.element.innerHTML = html.join('');
            },
          };
          var today   = new Date(),
          thisYear  = today.getFullYear(),
          thisMonth = today.getMonth(),
          thisDay   = today.getDate(),  //new
          months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
          
          calendar.days = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
          calendar.numYear = document.querySelector('#num_year'); 
          months.forEach((v,i) => {
          calendar.monthName = document.querySelector(`#${v}`);
          calendar.element = document.querySelectorAll('.table_month')[i];
          calendar.currentDay = i == thisMonth ? thisDay : false  //new
          calendar.update(thisYear, i);
          calendar.render();
          });
            
          
        </script>
      </body>
    </html>
а мне надо "подсветить" только 28 мая, только 28 мая, день недели Пт, и месяц Май...

другими словами надо присвоить дню недели в текущем месяце новый класс, а также текущему месяцу другой класс...

а датам относящие к апрелю и июню тоже присвоить классы...
0
123 / 98 / 15
Регистрация: 02.02.2014
Сообщений: 346
28.05.2021, 21:52
вижу только что в мае добавился класс

http://jsfiddle.net/nikolya223/w0qfdhb5/
0
 Аватар для Блондинка йа
13 / 12 / 1
Регистрация: 08.03.2019
Сообщений: 279
29.05.2021, 00:11  [ТС]
nikolya223, да, только в мае, но у обоих дат с числом 28

Добавлено через 12 минут
Скриншот:
0
 Аватар для Tavashi
1172 / 762 / 194
Регистрация: 21.05.2016
Сообщений: 1,858
29.05.2021, 03:59
PHP/HTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <style>
      @import url('https://fonts.googleapis.com/css?family=Baumans&display=swap');
 
      body {
        width: 1023px;
      }
 
      body,
      select,
      input {
        font: 14px serif;
      }
 
      #calendar {
        width: 330px;
        height: 375px;
        display: inline-block;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
 
      #navigation_panel {
        background-color: hsl(210, 100%, 92%);
        min-height: 34px;
        max-height: 78px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
        padding: 10px;
        margin-bottom: 5px;
        text-align: center;
        vertical-align: middle;
        display: -webkit-box;
        display: -webkit-flex;
        display: flex;
        -webkit-box-align: center;
        -webkit-align-items: center;
        align-items: center;
        -webkit-box-pack: center;
        -webkit-justify-content: center;
        justify-content: center;
        -webkit-flex-wrap: wrap;
        flex-wrap: wrap;
      }
 
      #navigation_panel button,
      #navigation_panel #calendar_year {
        background-color: hsl(210, 100%, 85%);
        color: hsl(210, 100%, 45%);
        font: 14px serif;
        border: 1px solid hsl(210, 100%, 45%);
      }
 
      #calendar_month {
        background-color: transparent;
        color: hsl(210, 100%, 45%);
        font: 14px serif;
        border: 1px solid hsl(210, 100%, 45%);
      }
 
      #navigation_panel button {
        height: 34px;
        vertical-align: middle;
      }
 
      #background_month {
        background-color: hsl(210, 100%, 85%);
        display: inline-block;
      }
 
      button.minus {
        width: 28px;
        text-align: center;
        border-radius: 12px 0 0 12px / 10px 0 0 10px;
        margin-right: -1px;
      }
 
      button.plus {
        width: 28px;
        text-align: center;
        border-radius: 0 12px 12px 0 / 0 10px 10px 0;
        margin-left: -1px;
      }
 
      .month_plus {
        margin-right: 35px;
      }
 
      .arrow {
        display: inline-block;
        line-height: 0.5;
      }
 
      #presently {
        width: 234px;
        margin-top: 10px;
        border-radius: 12px/10px;
      }
 
      #calendar_month {
        width: 89px;
        display: inline-block;
      }
 
      #calendar_year {
        width: 54px;
        display: inline-block;
      }
 
      select {
        height: 34px;
      }
 
      input {
        height: 30px;
        display: inline-block;
        text-align: center;
      }
 
      #table {
        font-family: 'Baumans', cursive;
        table-layout: fixed;
        width: 100%;
        height: 413px;
        padding: 2px;
      }
 
      #table,
      td {
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
      }
 
      td {
        margin: 1px;
        text-align: center;
      }
 
      #table tbody td.prevMonth {
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      }
 
      /* будние дни предыдущего месяца */
      #table tbody tr:nth-child(n + 6) td.prevMonth {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      }
 
      /* выходные дни предыдущего месяца */
      #table tbody td.nextMonth {
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      }
 
      /* будние дни следующего месяца */
      #table tbody tr:nth-child(n + 6) td.nextMonth {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      }
 
      /* выходные дни следующего месяца */
      #presently.hide {
        display: none;
      }
 
      #table tbody tr td.week-day {
        background-color: hsl(210, 100%, 85%);
        color: hsl(210, 100%, 50%);
        border: 1px solid hsl(0, 0%, 60%);
        width: 20%;
      }
 
      /* день недели */
      #table tbody tr:nth-child(n + 6) td.week-day {
        background-color: hsl(348, 100%, 85%);
        color: hsl(348, 100%, 50%);
        border: 1px solid hsl(0, 0%, 60%);
      }
 
      /* день недели выходной*/
      #table tbody tr td.week-day.curDay {
        border: 1px solid hsl(210, 100%, 50%);
        background-color: hsl(210, 100%, 75%);
        color: hsl(210, 100%, 98%);
        font-weight: bold;
        text-shadow:
          1px 1px hsl(210, 100%, 50%),
          -1px 1px hsl(210, 100%, 50%),
          1px -1px hsl(210, 100%, 50%),
          -1px -1px hsl(210, 100%, 50%),
          1px 0 hsl(210, 100%, 50%),
          0 1px hsl(210, 100%, 50%),
          -1px 0 hsl(210, 100%, 50%),
          0 -1px hsl(210, 100%, 50%);
        letter-spacing: 2px;
      }
 
      /* сегодн день недели */
      #table tbody tr:nth-child(n + 6) td.week-day.curDay {
        border: 1px solid hsl(348, 100%, 50%);
        background-color: hsl(348, 100%, 75%);
        color: hsl(348, 100%, 98%);
        font-weight: bold;
        text-shadow: 1px 1px hsl(348, 100%, 50%), 1px -1px hsl(348, 100%, 50%), -1px 1px hsl(348, 100%, 50%), -1px -1px hsl(348, 100%, 50%), 1px 0 hsl(348, 100%, 50%), -1px 0 hsl(348, 100%, 50%), 0 1px hsl(348, 100%, 50%), 0 -1px hsl(348, 100%, 50%);
        letter-spacing: 2px;
      }
 
      /* сегодн день недели выходной */
      #table tbody td {
        background-color: hsl(210, 100%, 90%);
        color: hsl(210, 100%, 50%);
      }
 
      /* будние дни текущего месяца */
      #table tbody tr:nth-child(n + 6) td {
        background-color: hsl(348, 100%, 90%);
        color: hsl(348, 100%, 50%);
      }
      
      /* выходные дни текущего месяца */
      #table tr td.curMonth.curDay {
        background-color: hsl(210, 100%, 80%);
        border: 1px solid hsl(210, 100%, 50%);
        font-weight: bold;
        color: hsl(210, 100%, 100%);
        text-shadow: 1px 1px hsl(210, 100%, 50%), -1px 1px hsl(210, 100%, 50%), 1px -1px hsl(210, 100%, 50%), -1px -1px hsl(210, 100%, 50%), 1px 0 hsl(210, 100%, 50%), 0 1px hsl(210, 100%, 50%), -1px 0 hsl(210, 100%, 50%), 0 -1px hsl(210, 100%, 50%);
        letter-spacing: 3px;
      }
 
      /* сегодня будний */
      #table tr:nth-child(n + 6) td.curMonth.curDay {
        background-color: hsl(348, 100%, 80%);
        border: 1px solid hsl(348, 100%, 50%);
        color: hsl(348, 100%, 100%);
        text-shadow: 1px 1px hsl(348, 100%, 50%), 1px -1px hsl(348, 100%, 50%), -1px 1px hsl(348, 100%, 50%), -1px -1px hsl(348, 100%, 50%), 1px 0 hsl(348, 100%, 50%), -1px 0 hsl(348, 100%, 50%), 0 1px hsl(348, 100%, 50%), 0 -1px hsl(348, 100%, 50%);
        letter-spacing: 3px;
      }
 
      /* сегодня выходной */
 
      #calendar {
        display: flex;
        flex-direction: column;
      }
 
      .content_month {
        flex: 1;
      }
 
      #table {
        height: 100%;
      }
 
      button,
      select,
      input {
        outline: none;
      }
      
      .td_month {
        width: 260px;
        height: 270px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
      }
 
      #num_year,
      #January,
      #February,
      #March,
      #April,
      #May,
      #June,
      #July,
      #August,
      #September,
      #October,
      #November,
      #December {
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 50%);
        font: bold 18px serif;
        text-align: center;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
 
      #num_year {
        font: bold 24px serif;
        width: auto;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
 
      #month1,
      #month2,
      #month3,
      #month4,
      #month5,
      #month6,
      #month7,
      #month8,
      #month9,
      #month10,
      #month11,
      #month12 {
        display: inline-block;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
        padding: 5px;
        width: auto;
      }
 
      .day {
        border: 1px solid hsl(0, 0%, 66%);
        width: auto;
        line-height: 30px;
        text-align: center;
        margin: 1px;
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 50%);
      }
 
      .table_month {
        table-layout: fixed;
        width: 100%;
        height: 220px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
      }
 
      .table_month tr td:nth-child(1) {
        width: 20%;
        font-weight: bold;
      }
 
      .table_month tr td.day:nth-child(1) {
        background-color: hsl(210, 100%, 88%);
        color: hsl(210, 100%, 60%);
      }
 
      .table_month tr:nth-child(n + 6) td.day:nth-child(1) {
        background-color: hsl(348, 100%, 88%);
        color: hsl(348, 100%, 60%);
      }
 
      .table_month tr:nth-child(n + 6) td.day {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 50%);
      }
 
      #year_input {
        border: 1px solid hsl(0, 0%, 66%);
        display: inline-block;
        text-align: center;
        font: bold 24px serif;
        color: hsl(210, 100%, 50%);
        width: 100px;
      }
      
 
    </style>
  </head>
 
  <body>
    <div id="num_year">
      Календарь на
      <button class="year_minus"></button>
      <input id="year_input" type="number" size="4" value="2021" />
      <button class="year_plus"></button>
      год.<br />
      <button id="presently">сегодня</button>
    </div>
    <table id="table">
      <tr>
        <td class="td_month">
          <div id="month1">
            <div id="January"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month2">
            <div id="February"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month3">
            <div id="March"></div>
            <table class="table_month"></table>
          </div>
        </td>
      </tr>
      <tr>
        <td class="td_month">
          <div id="month4">
            <div id="April"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month5">
            <div id="May"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month6">
            <div id="June"></div>
            <table class="table_month"></table>
          </div>
        </td>
      </tr>
      <tr>
        <td class="td_month">
          <div id="month7">
            <div id="July"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month8">
            <div id="August"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month9">
            <div id="September"></div>
            <table class="table_month"></table>
          </div>
        </td>
      </tr>
      <tr>
        <td class="td_month">
          <div id="month10">
            <div id="October"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month11">
            <div id="November"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month12">
            <div id="December"></div>
            <table class="table_month"></table>
          </div>
        </td>
      </tr>
    </table>
    <script>
      var calendar = {
        update: function(year, month) {
          this.year = year;
          this.month = ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'][month];
          var startDay = new Date(year, month, 1);
          var offsetDay = (startDay.getDay() || 7) - 1;
          startDay.setDate(startDay.getDate() - offsetDay);
          var lastDay = new Date(startDay);
          var days = new Date(year, month + 1, 0).getDate();
          days = Math.ceil((days + offsetDay) / 7) * 7;
          lastDay.setDate(lastDay.getDate() + days);
          this.data = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
          while (startDay < lastDay) {
            this.data.push(startDay.getDate());
            startDay.setHours(24);
          }
        },
        
        getCurDay: function(month, m, d, flag = false, flag2 = false) {
            let curDay;
            for (var i = 0; i < this.data.length; i++) {
            if (m === month) {
              if ((this.data[i] === 1 && flag) || flag2) {
                flag2 = true;
                continue;
              }
              if (this.data[i] === 1 || flag) {
                if (this.data[i] === d) curDay = i % 7;
                flag = true;
                continue;
              }
            }
          }
          return curDay;
        }, 
        
        render: function(month) {
          var html = ['<tr>', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>'];
          let m = new Date().getMonth(),
            d = new Date().getDate(),
            flag = false,
            flag2 = false,
            curDay = this.getCurDay(month, m, d);
          
          for (var i = 0; i < this.data.length; i++) {
            if (i >= 0 && i <= 6) {
                if (i === curDay) html[i % 7] += '<td class="week-day curDay">' + this.data[i];
              else html[i % 7] += '<td class="week-day">' + this.data[i];
              continue;
            }
            
            if (m === month) {
              let className = "curMonth";
              
              if ((this.data[i] === 1 && flag) || flag2) {
                flag2 = true;
                className = "prevMonth";
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              }
              
              if (this.data[i] === 1 || flag) {
                className = "curMonth";
                if (this.data[i] === d) className += " curDay";
                flag = true;
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              } else {
                className = "prevMonth";
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              }
            } else {
                html[i % 7] += '<td class="prevMonth">' + this.data[i];
            }
          }
          
          this.monthName.textContent = this.month;
          this.element.innerHTML = html.join('');
        }
      };
      
      var today = new Date(),
        thisYear = today.getFullYear(),
        thisMonth = today.getMonth(),
        months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
        year_minus = document.querySelector('.year_minus'),
        year_plus = document.querySelector('.year_plus'),
        buttonToday = document.querySelector('#presently'),
        yearListener = document.querySelector('#year_input');
 
      function make(year = thisYear) {
        months.forEach((v, i) => {
          calendar.monthName = document.querySelector(`#${v}`);
          calendar.element = document.querySelectorAll('.table_month')[i];
          calendar.update(year, i);
          calendar.render(i);
        });
      };
      make();
      buttonToday.classList.add('hide');
    
      year_plus.addEventListener('click', function() {
        yearListener.value = ++thisYear;
        if (yearListener.value == today.getFullYear()) buttonToday.classList.add('hide')
        else buttonToday.classList.remove('hide');
        make(thisYear);
      });
 
      year_minus.addEventListener('click', function() {
        yearListener.value = --thisYear;
        if (yearListener.value == today.getFullYear()) buttonToday.classList.add('hide')
        else buttonToday.classList.remove('hide');
        make(thisYear);
      });
      
      buttonToday.addEventListener('click', function() {
        thisYear = today.getFullYear();
        yearListener.value = thisYear;
        make(thisYear);
        buttonToday.classList.add('hide');
      });
      
    </script>
  </body>
</html>
0
 Аватар для Блондинка йа
13 / 12 / 1
Регистрация: 08.03.2019
Сообщений: 279
29.05.2021, 04:08  [ТС]
в текущем месяце надо выделить как на этом скриншоте ещё день недели, месяц, и даты других месяцев

а в остальных месяцах как на этом скриншоте только даты других месяцев...
0
 Аватар для Tavashi
1172 / 762 / 194
Регистрация: 21.05.2016
Сообщений: 1,858
29.05.2021, 04:47
PHP/HTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <style>
      @import url('https://fonts.googleapis.com/css?family=Baumans&display=swap');
 
      body {
        width: 1023px;
      }
 
      body,
      select,
      input {
        font: 14px serif;
      }
 
      #calendar {
        width: 330px;
        height: 375px;
        display: inline-block;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
 
      #navigation_panel {
        background-color: hsl(210, 100%, 92%);
        min-height: 34px;
        max-height: 78px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
        padding: 10px;
        margin-bottom: 5px;
        text-align: center;
        vertical-align: middle;
        display: -webkit-box;
        display: -webkit-flex;
        display: flex;
        -webkit-box-align: center;
        -webkit-align-items: center;
        align-items: center;
        -webkit-box-pack: center;
        -webkit-justify-content: center;
        justify-content: center;
        -webkit-flex-wrap: wrap;
        flex-wrap: wrap;
      }
 
      #navigation_panel button,
      #navigation_panel #calendar_year {
        background-color: hsl(210, 100%, 85%);
        color: hsl(210, 100%, 45%);
        font: 14px serif;
        border: 1px solid hsl(210, 100%, 45%);
      }
 
      #calendar_month {
        background-color: transparent;
        color: hsl(210, 100%, 45%);
        font: 14px serif;
        border: 1px solid hsl(210, 100%, 45%);
      }
 
      #navigation_panel button {
        height: 34px;
        vertical-align: middle;
      }
 
      #background_month {
        background-color: hsl(210, 100%, 85%);
        display: inline-block;
      }
 
      button.minus {
        width: 28px;
        text-align: center;
        border-radius: 12px 0 0 12px / 10px 0 0 10px;
        margin-right: -1px;
      }
 
      button.plus {
        width: 28px;
        text-align: center;
        border-radius: 0 12px 12px 0 / 0 10px 10px 0;
        margin-left: -1px;
      }
 
      .month_plus {
        margin-right: 35px;
      }
 
      .arrow {
        display: inline-block;
        line-height: 0.5;
      }
 
      #presently {
        width: 234px;
        margin-top: 10px;
        border-radius: 12px/10px;
      }
 
      #calendar_month {
        width: 89px;
        display: inline-block;
      }
 
      #calendar_year {
        width: 54px;
        display: inline-block;
      }
 
      select {
        height: 34px;
      }
 
      input {
        height: 30px;
        display: inline-block;
        text-align: center;
      }
 
      #table {
        font-family: 'Baumans', cursive;
        table-layout: fixed;
        width: 100%;
        height: 413px;
        padding: 2px;
      }
 
      #table,
      td {
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
      }
 
      td {
        margin: 1px;
        text-align: center;
      }
 
      #table tbody td.prevMonth {
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      }
 
      /* будние дни предыдущего месяца */
      #table tbody tr:nth-child(n + 6) td.prevMonth {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      }
 
      /* выходные дни предыдущего месяца */
      #table tbody td.nextMonth {
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      }
 
      /* будние дни следующего месяца */
      #table tbody tr:nth-child(n + 6) td.nextMonth {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      }
 
      /* выходные дни следующего месяца */
      #presently.hide {
        display: none;
      }
 
      #table tbody tr td.week-day {
        background-color: hsl(210, 100%, 85%);
        color: hsl(210, 100%, 50%);
        border: 1px solid hsl(0, 0%, 60%);
        width: 20%;
      }
 
      /* день недели */
      #table tbody tr:nth-child(n + 6) td.week-day {
        background-color: hsl(348, 100%, 85%);
        color: hsl(348, 100%, 50%);
        border: 1px solid hsl(0, 0%, 60%);
      }
 
      /* день недели выходной*/
      #table tbody tr td.week-day.curDay {
        border: 1px solid hsl(210, 100%, 50%);
        background-color: hsl(210, 100%, 75%);
        color: hsl(210, 100%, 98%);
        font-weight: bold;
        text-shadow:
          1px 1px hsl(210, 100%, 50%),
          -1px 1px hsl(210, 100%, 50%),
          1px -1px hsl(210, 100%, 50%),
          -1px -1px hsl(210, 100%, 50%),
          1px 0 hsl(210, 100%, 50%),
          0 1px hsl(210, 100%, 50%),
          -1px 0 hsl(210, 100%, 50%),
          0 -1px hsl(210, 100%, 50%);
        letter-spacing: 2px;
      }
 
      /* сегодн день недели */
      #table tbody tr:nth-child(n + 6) td.week-day.curDay {
        border: 1px solid hsl(348, 100%, 50%);
        background-color: hsl(348, 100%, 75%);
        color: hsl(348, 100%, 98%);
        font-weight: bold;
        text-shadow: 1px 1px hsl(348, 100%, 50%), 1px -1px hsl(348, 100%, 50%), -1px 1px hsl(348, 100%, 50%), -1px -1px hsl(348, 100%, 50%), 1px 0 hsl(348, 100%, 50%), -1px 0 hsl(348, 100%, 50%), 0 1px hsl(348, 100%, 50%), 0 -1px hsl(348, 100%, 50%);
        letter-spacing: 2px;
      }
 
      /* сегодн день недели выходной */
      #table tbody td {
        background-color: hsl(210, 100%, 90%);
        color: hsl(210, 100%, 50%);
      }
 
      /* будние дни текущего месяца */
      #table tbody tr:nth-child(n + 6) td {
        background-color: hsl(348, 100%, 90%);
        color: hsl(348, 100%, 50%);
      }
      
      /* выходные дни текущего месяца */
      #table tr td.curMonth.curDay {
        background-color: hsl(210, 100%, 80%);
        border: 1px solid hsl(210, 100%, 50%);
        font-weight: bold;
        color: hsl(210, 100%, 100%);
        text-shadow: 1px 1px hsl(210, 100%, 50%), -1px 1px hsl(210, 100%, 50%), 1px -1px hsl(210, 100%, 50%), -1px -1px hsl(210, 100%, 50%), 1px 0 hsl(210, 100%, 50%), 0 1px hsl(210, 100%, 50%), -1px 0 hsl(210, 100%, 50%), 0 -1px hsl(210, 100%, 50%);
        letter-spacing: 3px;
      }
 
      /* сегодня будний */
      #table tr:nth-child(n + 6) td.curMonth.curDay {
        background-color: hsl(348, 100%, 80%);
        border: 1px solid hsl(348, 100%, 50%);
        color: hsl(348, 100%, 100%);
        text-shadow: 1px 1px hsl(348, 100%, 50%), 1px -1px hsl(348, 100%, 50%), -1px 1px hsl(348, 100%, 50%), -1px -1px hsl(348, 100%, 50%), 1px 0 hsl(348, 100%, 50%), -1px 0 hsl(348, 100%, 50%), 0 1px hsl(348, 100%, 50%), 0 -1px hsl(348, 100%, 50%);
        letter-spacing: 3px;
      }
 
      /* сегодня выходной */
 
      #calendar {
        display: flex;
        flex-direction: column;
      }
 
      .content_month {
        flex: 1;
      }
 
      #table {
        height: 100%;
      }
 
      button,
      select,
      input {
        outline: none;
      }
      
      .td_month {
        width: 260px;
        height: 270px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
      }
 
      #num_year,
      #January,
      #February,
      #March,
      #April,
      #May,
      #June,
      #July,
      #August,
      #September,
      #October,
      #November,
      #December {
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 50%);
        font: bold 18px serif;
        text-align: center;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
 
      #num_year {
        font: bold 24px serif;
        width: auto;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
 
      #month1,
      #month2,
      #month3,
      #month4,
      #month5,
      #month6,
      #month7,
      #month8,
      #month9,
      #month10,
      #month11,
      #month12 {
        display: inline-block;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
        padding: 5px;
        width: auto;
      }
 
      .day {
        border: 1px solid hsl(0, 0%, 66%);
        width: auto;
        line-height: 30px;
        text-align: center;
        margin: 1px;
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 50%);
      }
 
      .table_month {
        table-layout: fixed;
        width: 100%;
        height: 220px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
      }
 
      .table_month tr td:nth-child(1) {
        width: 20%;
        font-weight: bold;
      }
 
      .table_month tr td.day:nth-child(1) {
        background-color: hsl(210, 100%, 88%);
        color: hsl(210, 100%, 60%);
      }
 
      .table_month tr:nth-child(n + 6) td.day:nth-child(1) {
        background-color: hsl(348, 100%, 88%);
        color: hsl(348, 100%, 60%);
      }
 
      .table_month tr:nth-child(n + 6) td.day {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 50%);
      }
 
      #year_input {
        border: 1px solid hsl(0, 0%, 66%);
        display: inline-block;
        text-align: center;
        font: bold 24px serif;
        color: hsl(210, 100%, 50%);
        width: 100px;
      }
      
 
    </style>
  </head>
 
  <body>
    <div id="num_year">
      Календарь на
      <button class="year_minus"></button>
      <input id="year_input" type="number" size="4" value="2021" />
      <button class="year_plus"></button>
      год.<br />
      <button id="presently">сегодня</button>
    </div>
    <table id="table">
      <tr>
        <td class="td_month">
          <div id="month1">
            <div id="January"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month2">
            <div id="February"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month3">
            <div id="March"></div>
            <table class="table_month"></table>
          </div>
        </td>
      </tr>
      <tr>
        <td class="td_month">
          <div id="month4">
            <div id="April"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month5">
            <div id="May"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month6">
            <div id="June"></div>
            <table class="table_month"></table>
          </div>
        </td>
      </tr>
      <tr>
        <td class="td_month">
          <div id="month7">
            <div id="July"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month8">
            <div id="August"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month9">
            <div id="September"></div>
            <table class="table_month"></table>
          </div>
        </td>
      </tr>
      <tr>
        <td class="td_month">
          <div id="month10">
            <div id="October"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month11">
            <div id="November"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month12">
            <div id="December"></div>
            <table class="table_month"></table>
          </div>
        </td>
      </tr>
    </table>
    <script>
      var calendar = {
        update: function(year, month) {
          this.year = year;
          this.month = ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'][month];
          var startDay = new Date(year, month, 1);
          var offsetDay = (startDay.getDay() || 7) - 1;
          startDay.setDate(startDay.getDate() - offsetDay);
          var lastDay = new Date(startDay);
          var days = new Date(year, month + 1, 0).getDate();
          days = Math.ceil((days + offsetDay) / 7) * 7;
          lastDay.setDate(lastDay.getDate() + days);
          this.data = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
          while (startDay < lastDay) {
            this.data.push(startDay.getDate());
            startDay.setHours(24);
          }
        },
        
        getCurDay: function(month, m, d, flag = false, flag2 = false) {
            let curDay;
            for (var i = 0; i < this.data.length; i++) {
            if (m === month) {
              if ((this.data[i] === 1 && flag) || flag2) {
                flag2 = true;
                continue;
              }
              if (this.data[i] === 1 || flag) {
                if (this.data[i] === d) curDay = i % 7;
                flag = true;
                continue;
              }
            }
          }
          return curDay;
        }, 
        
        render: function(month, name) {
          var html = ['<tr>', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>'];
          let m = new Date().getMonth(),
            d = new Date().getDate(),
            flag = false,
            flag2 = false,
            curDay = this.getCurDay(month, m, d),
            className;
          
          for (var i = 0; i < this.data.length; i++) {
            if (i >= 0 && i <= 6) {
                if (i === curDay) html[i % 7] += '<td class="week-day curDay">' + this.data[i];
              else html[i % 7] += '<td class="week-day">' + this.data[i];
              continue;
            }
             
              if ((this.data[i] === 1 && flag) || flag2) {
                flag2 = true;
                className = "prevMonth";
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              }
              
              if (this.data[i] === 1 || flag) {
                className = "curMonth";
                if (this.data[i] === d && m === month) {
                  className += " curDay";
                  document.querySelector(`#${name}`).style.color = "red";
                }
                flag = true;
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              } else {
                className = "prevMonth";
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              }
              
              html[i % 7] += '<td class="prevMonth">' + this.data[i];
          }
          
          this.monthName.textContent = this.month;
          this.element.innerHTML = html.join('');
        }
      };
      
      var today = new Date(),
        thisYear = today.getFullYear(),
        thisMonth = today.getMonth(),
        months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
        year_minus = document.querySelector('.year_minus'),
        year_plus = document.querySelector('.year_plus'),
        buttonToday = document.querySelector('#presently'),
        yearListener = document.querySelector('#year_input');
 
      function make(year = thisYear) {
        months.forEach((v, i) => {
          calendar.monthName = document.querySelector(`#${v}`);
          calendar.element = document.querySelectorAll('.table_month')[i];
          calendar.update(year, i);
          calendar.render(i, months[i]);
        });
      };
      make();
      buttonToday.classList.add('hide');
    
      year_plus.addEventListener('click', function() {
        yearListener.value = ++thisYear;
        if (yearListener.value == today.getFullYear()) buttonToday.classList.add('hide')
        else buttonToday.classList.remove('hide');
        make(thisYear);
      });
 
      year_minus.addEventListener('click', function() {
        yearListener.value = --thisYear;
        if (yearListener.value == today.getFullYear()) buttonToday.classList.add('hide')
        else buttonToday.classList.remove('hide');
        make(thisYear);
      });
      
      buttonToday.addEventListener('click', function() {
        thisYear = today.getFullYear();
        yearListener.value = thisYear;
        make(thisYear);
        buttonToday.classList.add('hide');
      });
      
    </script>
  </body>
</html>
0
 Аватар для Tavashi
1172 / 762 / 194
Регистрация: 21.05.2016
Сообщений: 1,858
29.05.2021, 05:05
Лучший ответ Сообщение было отмечено Блондинка йа как решение

Решение

Поменял цвет:
PHP/HTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <style>
      @import url('https://fonts.googleapis.com/css?family=Baumans&display=swap');
 
      body {
        width: 1023px;
      }
 
      body,
      select,
      input {
        font: 14px serif;
      }
 
      #calendar {
        width: 330px;
        height: 375px;
        display: inline-block;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
 
      #navigation_panel {
        background-color: hsl(210, 100%, 92%);
        min-height: 34px;
        max-height: 78px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
        padding: 10px;
        margin-bottom: 5px;
        text-align: center;
        vertical-align: middle;
        display: -webkit-box;
        display: -webkit-flex;
        display: flex;
        -webkit-box-align: center;
        -webkit-align-items: center;
        align-items: center;
        -webkit-box-pack: center;
        -webkit-justify-content: center;
        justify-content: center;
        -webkit-flex-wrap: wrap;
        flex-wrap: wrap;
      }
 
      #navigation_panel button,
      #navigation_panel #calendar_year {
        background-color: hsl(210, 100%, 85%);
        color: hsl(210, 100%, 45%);
        font: 14px serif;
        border: 1px solid hsl(210, 100%, 45%);
      }
 
      #calendar_month {
        background-color: transparent;
        color: hsl(210, 100%, 45%);
        font: 14px serif;
        border: 1px solid hsl(210, 100%, 45%);
      }
 
      #navigation_panel button {
        height: 34px;
        vertical-align: middle;
      }
 
      #background_month {
        background-color: hsl(210, 100%, 85%);
        display: inline-block;
      }
 
      button.minus {
        width: 28px;
        text-align: center;
        border-radius: 12px 0 0 12px / 10px 0 0 10px;
        margin-right: -1px;
      }
 
      button.plus {
        width: 28px;
        text-align: center;
        border-radius: 0 12px 12px 0 / 0 10px 10px 0;
        margin-left: -1px;
      }
 
      .month_plus {
        margin-right: 35px;
      }
 
      .arrow {
        display: inline-block;
        line-height: 0.5;
      }
 
      #presently {
        width: 234px;
        margin-top: 10px;
        border-radius: 12px/10px;
      }
 
      #calendar_month {
        width: 89px;
        display: inline-block;
      }
 
      #calendar_year {
        width: 54px;
        display: inline-block;
      }
 
      select {
        height: 34px;
      }
 
      input {
        height: 30px;
        display: inline-block;
        text-align: center;
      }
 
      #table {
        font-family: 'Baumans', cursive;
        table-layout: fixed;
        width: 100%;
        height: 413px;
        padding: 2px;
      }
 
      #table,
      td {
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
      }
 
      td {
        margin: 1px;
        text-align: center;
      }
 
      #table tbody td.prevMonth {
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      }
 
      /* будние дни предыдущего месяца */
      #table tbody tr:nth-child(n + 6) td.prevMonth {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      }
 
      /* выходные дни предыдущего месяца */
      #table tbody td.nextMonth {
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      }
 
      /* будние дни следующего месяца */
      #table tbody tr:nth-child(n + 6) td.nextMonth {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      }
 
      /* выходные дни следующего месяца */
      #presently.hide {
        display: none;
      }
 
      #table tbody tr td.week-day {
        background-color: hsl(210, 100%, 85%);
        color: hsl(210, 100%, 50%);
        border: 1px solid hsl(0, 0%, 60%);
        width: 20%;
      }
 
      /* день недели */
      #table tbody tr:nth-child(n + 6) td.week-day {
        background-color: hsl(348, 100%, 85%);
        color: hsl(348, 100%, 50%);
        border: 1px solid hsl(0, 0%, 60%);
      }
 
      /* день недели выходной*/
      #table tbody tr td.week-day.curDay {
        border: 1px solid hsl(210, 100%, 50%);
        background-color: hsl(134, 100%, 50%); /**/
        color: hsl(210, 100%, 98%);
        font-weight: bold;
        text-shadow:
          1px 1px hsl(210, 100%, 50%),
          -1px 1px hsl(210, 100%, 50%),
          1px -1px hsl(210, 100%, 50%),
          -1px -1px hsl(210, 100%, 50%),
          1px 0 hsl(210, 100%, 50%),
          0 1px hsl(210, 100%, 50%),
          -1px 0 hsl(210, 100%, 50%),
          0 -1px hsl(210, 100%, 50%);
        letter-spacing: 2px;
      }
 
      /* сегодн день недели */
      #table tbody tr:nth-child(n + 6) td.week-day.curDay {
        border: 1px solid hsl(348, 100%, 50%);
        background-color: hsl(134, 100%, 50%); /**/
        color: hsl(348, 100%, 98%);
        font-weight: bold;
        text-shadow: 1px 1px hsl(348, 100%, 50%), 1px -1px hsl(348, 100%, 50%), -1px 1px hsl(348, 100%, 50%), -1px -1px hsl(348, 100%, 50%), 1px 0 hsl(348, 100%, 50%), -1px 0 hsl(348, 100%, 50%), 0 1px hsl(348, 100%, 50%), 0 -1px hsl(348, 100%, 50%);
        letter-spacing: 2px;
      }
 
      /* сегодн день недели выходной */
      #table tbody td {
        background-color: hsl(210, 100%, 90%);
        color: hsl(210, 100%, 50%);
      }
 
      /* будние дни текущего месяца */
      #table tbody tr:nth-child(n + 6) td {
        background-color: hsl(348, 100%, 90%);
        color: hsl(348, 100%, 50%);
      }
      
      /* выходные дни текущего месяца */
      #table tr td.curMonth.curDay {
        background-color: hsl(134, 100%, 50%); /**/
        border: 1px solid hsl(210, 100%, 50%);
        font-weight: bold;
        color: hsl(210, 100%, 100%);
        text-shadow: 1px 1px hsl(210, 100%, 50%), -1px 1px hsl(210, 100%, 50%), 1px -1px hsl(210, 100%, 50%), -1px -1px hsl(210, 100%, 50%), 1px 0 hsl(210, 100%, 50%), 0 1px hsl(210, 100%, 50%), -1px 0 hsl(210, 100%, 50%), 0 -1px hsl(210, 100%, 50%);
        letter-spacing: 3px;
      }
 
      /* сегодня будний */
      #table tr:nth-child(n + 6) td.curMonth.curDay {
        background-color: hsl(134, 100%, 50%); /**/
        border: 1px solid hsl(348, 100%, 50%);
        color: hsl(348, 100%, 100%);
        text-shadow: 1px 1px hsl(348, 100%, 50%), 1px -1px hsl(348, 100%, 50%), -1px 1px hsl(348, 100%, 50%), -1px -1px hsl(348, 100%, 50%), 1px 0 hsl(348, 100%, 50%), -1px 0 hsl(348, 100%, 50%), 0 1px hsl(348, 100%, 50%), 0 -1px hsl(348, 100%, 50%);
        letter-spacing: 3px;
      }
 
      /* сегодня выходной */
 
      #calendar {
        display: flex;
        flex-direction: column;
      }
 
      .content_month {
        flex: 1;
      }
 
      #table {
        height: 100%;
      }
 
      button,
      select,
      input {
        outline: none;
      }
      
      .td_month {
        width: 260px;
        height: 270px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
      }
 
      #num_year,
      #January,
      #February,
      #March,
      #April,
      #May,
      #June,
      #July,
      #August,
      #September,
      #October,
      #November,
      #December {
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 50%);
        font: bold 18px serif;
        text-align: center;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
 
      #num_year {
        font: bold 24px serif;
        width: auto;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
 
      #month1,
      #month2,
      #month3,
      #month4,
      #month5,
      #month6,
      #month7,
      #month8,
      #month9,
      #month10,
      #month11,
      #month12 {
        display: inline-block;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
        padding: 5px;
        width: auto;
      }
 
      .day {
        border: 1px solid hsl(0, 0%, 66%);
        width: auto;
        line-height: 30px;
        text-align: center;
        margin: 1px;
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 50%);
      }
 
      .table_month {
        table-layout: fixed;
        width: 100%;
        height: 220px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
      }
 
      .table_month tr td:nth-child(1) {
        width: 20%;
        font-weight: bold;
      }
 
      .table_month tr td.day:nth-child(1) {
        background-color: hsl(210, 100%, 88%);
        color: hsl(210, 100%, 60%);
      }
 
      .table_month tr:nth-child(n + 6) td.day:nth-child(1) {
        background-color: hsl(348, 100%, 88%);
        color: hsl(348, 100%, 60%);
      }
 
      .table_month tr:nth-child(n + 6) td.day {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 50%);
      }
 
      #year_input {
        border: 1px solid hsl(0, 0%, 66%);
        display: inline-block;
        text-align: center;
        font: bold 24px serif;
        color: hsl(210, 100%, 50%);
        width: 100px;
      }
      
 
    </style>
  </head>
 
  <body>
    <div id="num_year">
      Календарь на
      <button class="year_minus"></button>
      <input id="year_input" type="number" size="4" value="2021" />
      <button class="year_plus"></button>
      год.<br />
      <button id="presently">сегодня</button>
    </div>
    <table id="table">
      <tr>
        <td class="td_month">
          <div id="month1">
            <div id="January"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month2">
            <div id="February"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month3">
            <div id="March"></div>
            <table class="table_month"></table>
          </div>
        </td>
      </tr>
      <tr>
        <td class="td_month">
          <div id="month4">
            <div id="April"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month5">
            <div id="May"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month6">
            <div id="June"></div>
            <table class="table_month"></table>
          </div>
        </td>
      </tr>
      <tr>
        <td class="td_month">
          <div id="month7">
            <div id="July"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month8">
            <div id="August"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month9">
            <div id="September"></div>
            <table class="table_month"></table>
          </div>
        </td>
      </tr>
      <tr>
        <td class="td_month">
          <div id="month10">
            <div id="October"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month11">
            <div id="November"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month12">
            <div id="December"></div>
            <table class="table_month"></table>
          </div>
        </td>
      </tr>
    </table>
    <script>
      var calendar = {
        update: function(year, month) {
          this.year = year;
          this.month = ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'][month];
          var startDay = new Date(year, month, 1);
          var offsetDay = (startDay.getDay() || 7) - 1;
          startDay.setDate(startDay.getDate() - offsetDay);
          var lastDay = new Date(startDay);
          var days = new Date(year, month + 1, 0).getDate();
          days = Math.ceil((days + offsetDay) / 7) * 7;
          lastDay.setDate(lastDay.getDate() + days);
          this.data = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
          while (startDay < lastDay) {
            this.data.push(startDay.getDate());
            startDay.setHours(24);
          }
        },
        
        getCurDay: function(month, m, d, flag = false, flag2 = false) {
            let curDay;
            for (var i = 0; i < this.data.length; i++) {
            if (m === month) {
              if ((this.data[i] === 1 && flag) || flag2) {
                flag2 = true;
                continue;
              }
              if (this.data[i] === 1 || flag) {
                if (this.data[i] === d) curDay = i % 7;
                flag = true;
                continue;
              }
            }
          }
          return curDay;
        }, 
        
        render: function(month, name) {
          var html = ['<tr>', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>'];
          let m = new Date().getMonth(),
            d = new Date().getDate(),
            flag = false,
            flag2 = false,
            curDay = this.getCurDay(month, m, d),
            className;
          
          for (var i = 0; i < this.data.length; i++) {
            if (i >= 0 && i <= 6) {
                if (i === curDay) html[i % 7] += '<td class="week-day curDay">' + this.data[i];
              else html[i % 7] += '<td class="week-day">' + this.data[i];
              continue;
            }
             
              if ((this.data[i] === 1 && flag) || flag2) {
                flag2 = true;
                className = "prevMonth";
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              }
              
              if (this.data[i] === 1 || flag) {
                className = "curMonth";
                if (this.data[i] === d && m === month) {
                  className += " curDay";
                  document.querySelector(`#${name}`).style.backgroundColor = "#90EE90";
                }
                flag = true;
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              } else {
                className = "prevMonth";
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              }
              
              html[i % 7] += '<td class="prevMonth">' + this.data[i];
          }
          
          this.monthName.textContent = this.month;
          this.element.innerHTML = html.join('');
        }
      };
      
      var today = new Date(),
        thisYear = today.getFullYear(),
        thisMonth = today.getMonth(),
        months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
        year_minus = document.querySelector('.year_minus'),
        year_plus = document.querySelector('.year_plus'),
        buttonToday = document.querySelector('#presently'),
        yearListener = document.querySelector('#year_input');
 
      function make(year = thisYear) {
        months.forEach((v, i) => {
          calendar.monthName = document.querySelector(`#${v}`);
          calendar.element = document.querySelectorAll('.table_month')[i];
          calendar.update(year, i);
          calendar.render(i, months[i]);
        });
      };
      make();
      buttonToday.classList.add('hide');
    
      year_plus.addEventListener('click', function() {
        yearListener.value = ++thisYear;
        if (yearListener.value == today.getFullYear()) buttonToday.classList.add('hide')
        else buttonToday.classList.remove('hide');
        make(thisYear);
      });
 
      year_minus.addEventListener('click', function() {
        yearListener.value = --thisYear;
        if (yearListener.value == today.getFullYear()) buttonToday.classList.add('hide')
        else buttonToday.classList.remove('hide');
        make(thisYear);
      });
      
      buttonToday.addEventListener('click', function() {
        thisYear = today.getFullYear();
        yearListener.value = thisYear;
        make(thisYear);
        buttonToday.classList.add('hide');
      });
      
    </script>
  </body>
</html>
0
 Аватар для Блондинка йа
13 / 12 / 1
Регистрация: 08.03.2019
Сообщений: 279
29.05.2021, 06:05  [ТС]
ну html и css я знаю намного лучше, а вот с js не получается выучить :-(

Добавлено через 41 минуту
Tavashi, а можно чуть подробнее что значат строки 531-536

JavaScript
1
2
3
4
5
6
if (this.data[i] === 1 || flag) {
                className = "curMonth";
                if (this.data[i] === d && m === month) {
                  className += " curDay";
                  document.querySelector(`#${name}`).style.color = "red";
                }
?

просто думала что лучше просто присвоить отдельный класс, и название месяца выделить как название текущего дня недели

CSS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
border: 1px solid hsl(210, 100%, 50%);
        background-color: hsl(210, 100%, 75%);
        color: hsl(210, 100%, 98%);
        font-weight: bold;
        text-shadow:
          1px 1px hsl(210, 100%, 50%),
          -1px 1px hsl(210, 100%, 50%),
          1px -1px hsl(210, 100%, 50%),
          -1px -1px hsl(210, 100%, 50%),
          1px 0 hsl(210, 100%, 50%),
          0 1px hsl(210, 100%, 50%),
          -1px 0 hsl(210, 100%, 50%),
          0 -1px hsl(210, 100%, 50%);
        letter-spacing: 2px;
Добавлено через 8 минут
и почему-то не срабатывает ввод года с клавиатуры, кнопки ➕ и ➖ срабатывают, а когда ввожу другой год в поле ввода, календарь не переключается...
0
 Аватар для Tavashi
1172 / 762 / 194
Регистрация: 21.05.2016
Сообщений: 1,858
29.05.2021, 06:15
Цитата Сообщение от Блондинка йа Посмотреть сообщение
что значат строки 531-536
Смысл такой, что нам нужно сначала поймать первую часть текущего месяца, то есть те ячейки таблицы (месяца), которые начнутся с единицы (1-ое число месяца). А все, что до этого - считать не интересующим нас месяцем с соответсвующими стилями. Далее, нам нужно поймать второе "появление" единички, но это уже будет относится к другому месяцу, к которому нужно применять другие стили.

Добавлено через 9 минут
Цитата Сообщение от Блондинка йа Посмотреть сообщение
когда ввожу другой год в поле ввода, календарь не переключается
Исправил, проверяйте:
PHP/HTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <style>
      @import url('https://fonts.googleapis.com/css?family=Baumans&display=swap');
 
      body {
        width: 1023px;
      }
 
      body,
      select,
      input {
        font: 14px serif;
      }
 
      #calendar {
        width: 330px;
        height: 375px;
        display: inline-block;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
 
      #navigation_panel {
        background-color: hsl(210, 100%, 92%);
        min-height: 34px;
        max-height: 78px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
        padding: 10px;
        margin-bottom: 5px;
        text-align: center;
        vertical-align: middle;
        display: -webkit-box;
        display: -webkit-flex;
        display: flex;
        -webkit-box-align: center;
        -webkit-align-items: center;
        align-items: center;
        -webkit-box-pack: center;
        -webkit-justify-content: center;
        justify-content: center;
        -webkit-flex-wrap: wrap;
        flex-wrap: wrap;
      }
 
      #navigation_panel button,
      #navigation_panel #calendar_year {
        background-color: hsl(210, 100%, 85%);
        color: hsl(210, 100%, 45%);
        font: 14px serif;
        border: 1px solid hsl(210, 100%, 45%);
      }
 
      #calendar_month {
        background-color: transparent;
        color: hsl(210, 100%, 45%);
        font: 14px serif;
        border: 1px solid hsl(210, 100%, 45%);
      }
 
      #navigation_panel button {
        height: 34px;
        vertical-align: middle;
      }
 
      #background_month {
        background-color: hsl(210, 100%, 85%);
        display: inline-block;
      }
 
      button.minus {
        width: 28px;
        text-align: center;
        border-radius: 12px 0 0 12px / 10px 0 0 10px;
        margin-right: -1px;
      }
 
      button.plus {
        width: 28px;
        text-align: center;
        border-radius: 0 12px 12px 0 / 0 10px 10px 0;
        margin-left: -1px;
      }
 
      .month_plus {
        margin-right: 35px;
      }
 
      .arrow {
        display: inline-block;
        line-height: 0.5;
      }
 
      #presently {
        width: 234px;
        margin-top: 10px;
        border-radius: 12px/10px;
      }
 
      #calendar_month {
        width: 89px;
        display: inline-block;
      }
 
      #calendar_year {
        width: 54px;
        display: inline-block;
      }
 
      select {
        height: 34px;
      }
 
      input {
        height: 30px;
        display: inline-block;
        text-align: center;
      }
 
      #table {
        font-family: 'Baumans', cursive;
        table-layout: fixed;
        width: 100%;
        height: 413px;
        padding: 2px;
      }
 
      #table,
      td {
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
      }
 
      td {
        margin: 1px;
        text-align: center;
      }
 
      #table tbody td.prevMonth {
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      }
 
      /* будние дни предыдущего месяца */
      #table tbody tr:nth-child(n + 6) td.prevMonth {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      }
 
      /* выходные дни предыдущего месяца */
      #table tbody td.nextMonth {
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      }
 
      /* будние дни следующего месяца */
      #table tbody tr:nth-child(n + 6) td.nextMonth {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      }
 
      /* выходные дни следующего месяца */
      #presently.hide {
        display: none;
      }
 
      #table tbody tr td.week-day {
        background-color: hsl(210, 100%, 85%);
        color: hsl(210, 100%, 50%);
        border: 1px solid hsl(0, 0%, 60%);
        width: 20%;
      }
 
      /* день недели */
      #table tbody tr:nth-child(n + 6) td.week-day {
        background-color: hsl(348, 100%, 85%);
        color: hsl(348, 100%, 50%);
        border: 1px solid hsl(0, 0%, 60%);
      }
 
      /* день недели выходной*/
      #table tbody tr td.week-day.curDay {
        border: 1px solid hsl(210, 100%, 50%);
        background-color: hsl(134, 100%, 50%); /**/
        color: hsl(210, 100%, 98%);
        font-weight: bold;
        text-shadow:
          1px 1px hsl(210, 100%, 50%),
          -1px 1px hsl(210, 100%, 50%),
          1px -1px hsl(210, 100%, 50%),
          -1px -1px hsl(210, 100%, 50%),
          1px 0 hsl(210, 100%, 50%),
          0 1px hsl(210, 100%, 50%),
          -1px 0 hsl(210, 100%, 50%),
          0 -1px hsl(210, 100%, 50%);
        letter-spacing: 2px;
      }
 
      /* сегодн день недели */
      #table tbody tr:nth-child(n + 6) td.week-day.curDay {
        border: 1px solid hsl(348, 100%, 50%);
        background-color: hsl(134, 100%, 50%); /**/
        color: hsl(348, 100%, 98%);
        font-weight: bold;
        text-shadow: 1px 1px hsl(348, 100%, 50%), 1px -1px hsl(348, 100%, 50%), -1px 1px hsl(348, 100%, 50%), -1px -1px hsl(348, 100%, 50%), 1px 0 hsl(348, 100%, 50%), -1px 0 hsl(348, 100%, 50%), 0 1px hsl(348, 100%, 50%), 0 -1px hsl(348, 100%, 50%);
        letter-spacing: 2px;
      }
 
      /* сегодн день недели выходной */
      #table tbody td {
        background-color: hsl(210, 100%, 90%);
        color: hsl(210, 100%, 50%);
      }
 
      /* будние дни текущего месяца */
      #table tbody tr:nth-child(n + 6) td {
        background-color: hsl(348, 100%, 90%);
        color: hsl(348, 100%, 50%);
      }
      
      /* выходные дни текущего месяца */
      #table tr td.curMonth.curDay {
        background-color: hsl(134, 100%, 50%); /**/
        border: 1px solid hsl(210, 100%, 50%);
        font-weight: bold;
        color: hsl(210, 100%, 100%);
        text-shadow: 1px 1px hsl(210, 100%, 50%), -1px 1px hsl(210, 100%, 50%), 1px -1px hsl(210, 100%, 50%), -1px -1px hsl(210, 100%, 50%), 1px 0 hsl(210, 100%, 50%), 0 1px hsl(210, 100%, 50%), -1px 0 hsl(210, 100%, 50%), 0 -1px hsl(210, 100%, 50%);
        letter-spacing: 3px;
      }
 
      /* сегодня будний */
      #table tr:nth-child(n + 6) td.curMonth.curDay {
        background-color: hsl(134, 100%, 50%); /**/
        border: 1px solid hsl(348, 100%, 50%);
        color: hsl(348, 100%, 100%);
        text-shadow: 1px 1px hsl(348, 100%, 50%), 1px -1px hsl(348, 100%, 50%), -1px 1px hsl(348, 100%, 50%), -1px -1px hsl(348, 100%, 50%), 1px 0 hsl(348, 100%, 50%), -1px 0 hsl(348, 100%, 50%), 0 1px hsl(348, 100%, 50%), 0 -1px hsl(348, 100%, 50%);
        letter-spacing: 3px;
      }
 
      /* сегодня выходной */
 
      #calendar {
        display: flex;
        flex-direction: column;
      }
 
      .content_month {
        flex: 1;
      }
 
      #table {
        height: 100%;
      }
 
      button,
      select,
      input {
        outline: none;
      }
      
      .td_month {
        width: 260px;
        height: 270px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
      }
 
      #num_year,
      #January,
      #February,
      #March,
      #April,
      #May,
      #June,
      #July,
      #August,
      #September,
      #October,
      #November,
      #December {
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 50%);
        font: bold 18px serif;
        text-align: center;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
 
      #num_year {
        font: bold 24px serif;
        width: auto;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
 
      #month1,
      #month2,
      #month3,
      #month4,
      #month5,
      #month6,
      #month7,
      #month8,
      #month9,
      #month10,
      #month11,
      #month12 {
        display: inline-block;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
        padding: 5px;
        width: auto;
      }
 
      .day {
        border: 1px solid hsl(0, 0%, 66%);
        width: auto;
        line-height: 30px;
        text-align: center;
        margin: 1px;
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 50%);
      }
 
      .table_month {
        table-layout: fixed;
        width: 100%;
        height: 220px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
      }
 
      .table_month tr td:nth-child(1) {
        width: 20%;
        font-weight: bold;
      }
 
      .table_month tr td.day:nth-child(1) {
        background-color: hsl(210, 100%, 88%);
        color: hsl(210, 100%, 60%);
      }
 
      .table_month tr:nth-child(n + 6) td.day:nth-child(1) {
        background-color: hsl(348, 100%, 88%);
        color: hsl(348, 100%, 60%);
      }
 
      .table_month tr:nth-child(n + 6) td.day {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 50%);
      }
 
      #year_input {
        border: 1px solid hsl(0, 0%, 66%);
        display: inline-block;
        text-align: center;
        font: bold 24px serif;
        color: hsl(210, 100%, 50%);
        width: 100px;
      }
      
 
    </style>
  </head>
 
  <body>
    <div id="num_year">
      Календарь на
      <button class="year_minus"></button>
      <input id="year_input" type="number" size="4" value="2021" />
      <button class="year_plus"></button>
      год.<br />
      <button id="presently">сегодня</button>
    </div>
    <table id="table">
      <tr>
        <td class="td_month">
          <div id="month1">
            <div id="January"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month2">
            <div id="February"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month3">
            <div id="March"></div>
            <table class="table_month"></table>
          </div>
        </td>
      </tr>
      <tr>
        <td class="td_month">
          <div id="month4">
            <div id="April"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month5">
            <div id="May"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month6">
            <div id="June"></div>
            <table class="table_month"></table>
          </div>
        </td>
      </tr>
      <tr>
        <td class="td_month">
          <div id="month7">
            <div id="July"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month8">
            <div id="August"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month9">
            <div id="September"></div>
            <table class="table_month"></table>
          </div>
        </td>
      </tr>
      <tr>
        <td class="td_month">
          <div id="month10">
            <div id="October"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month11">
            <div id="November"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month12">
            <div id="December"></div>
            <table class="table_month"></table>
          </div>
        </td>
      </tr>
    </table>
    <script>
      var calendar = {
        update: function(year, month) {
          this.year = year;
          this.month = ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'][month];
          var startDay = new Date(year, month, 1);
          var offsetDay = (startDay.getDay() || 7) - 1;
          startDay.setDate(startDay.getDate() - offsetDay);
          var lastDay = new Date(startDay);
          var days = new Date(year, month + 1, 0).getDate();
          days = Math.ceil((days + offsetDay) / 7) * 7;
          lastDay.setDate(lastDay.getDate() + days);
          this.data = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
          while (startDay < lastDay) {
            this.data.push(startDay.getDate());
            startDay.setHours(24);
          }
        },
        
        getCurDay: function(month, m, d, flag = false, flag2 = false) {
            let curDay;
            for (var i = 0; i < this.data.length; i++) {
            if (m === month) {
              if ((this.data[i] === 1 && flag) || flag2) {
                flag2 = true;
                continue;
              }
              if (this.data[i] === 1 || flag) {
                if (this.data[i] === d) curDay = i % 7;
                flag = true;
                continue;
              }
            }
          }
          return curDay;
        }, 
        
        render: function(month, name) {
          var html = ['<tr>', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>'];
          let m = new Date().getMonth(),
            d = new Date().getDate(),
            flag = false,
            flag2 = false,
            curDay = this.getCurDay(month, m, d),
            className;
          
          for (var i = 0; i < this.data.length; i++) {
            if (i >= 0 && i <= 6) {
                if (i === curDay) html[i % 7] += '<td class="week-day curDay">' + this.data[i];
              else html[i % 7] += '<td class="week-day">' + this.data[i];
              continue;
            }
             
              if ((this.data[i] === 1 && flag) || flag2) {
                flag2 = true;
                className = "prevMonth";
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              }
              
              if (this.data[i] === 1 || flag) {
                className = "curMonth";
                if (this.data[i] === d && m === month) {
                  className += " curDay";
                  document.querySelector(`#${name}`).style.backgroundColor = "#90EE90";
                }
                flag = true;
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              } else {
                className = "prevMonth";
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              }
              
              html[i % 7] += '<td class="prevMonth">' + this.data[i];
          }
          
          this.monthName.textContent = this.month;
          this.element.innerHTML = html.join('');
        }
      };
      
      var today = new Date(),
        thisYear = today.getFullYear(),
        thisMonth = today.getMonth(),
        months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
        year_minus = document.querySelector('.year_minus'),
        year_plus = document.querySelector('.year_plus'),
        buttonToday = document.querySelector('#presently'),
        yearListener = document.querySelector('#year_input');
 
      function make(year = thisYear) {
        months.forEach((v, i) => {
          calendar.monthName = document.querySelector(`#${v}`);
          calendar.element = document.querySelectorAll('.table_month')[i];
          calendar.update(year, i);
          calendar.render(i, months[i]);
        });
      };
      make();
      buttonToday.classList.add('hide');
    
      year_plus.addEventListener('click', function() {
        yearListener.value = ++thisYear;
        if (yearListener.value == today.getFullYear()) buttonToday.classList.add('hide')
        else buttonToday.classList.remove('hide');
        make(thisYear);
      });
 
      year_minus.addEventListener('click', function() {
        yearListener.value = --thisYear;
        if (yearListener.value == today.getFullYear()) buttonToday.classList.add('hide')
        else buttonToday.classList.remove('hide');
        make(thisYear);
      });
      
      buttonToday.addEventListener('click', function() {
        thisYear = today.getFullYear();
        yearListener.value = thisYear;
        make(thisYear);
        buttonToday.classList.add('hide');
      });
      
      yearListener.addEventListener('change', function() {
        thisYear = yearListener.value;
        if (yearListener.value == today.getFullYear()) buttonToday.classList.add('hide')
        else buttonToday.classList.remove('hide');
        make(+yearListener.value);
      });
      
    </script>
  </body>
</html>
0
 Аватар для Блондинка йа
13 / 12 / 1
Регистрация: 08.03.2019
Сообщений: 279
29.05.2021, 06:37  [ТС]
Цитата Сообщение от Tavashi Посмотреть сообщение
Смысл такой, что нам нужно сначала поймать первую часть текущего месяца, то есть те ячейки таблицы (месяца), которые начнутся с единицы (1-ое число месяца). А все, что до этого - считать не интересующим нас месяцем с соответсвующими стилями. Далее, нам нужно поймать второе "появление" единички, но это уже будет относится к другому месяцу, к которому нужно применять другие стили.
просто думала что диву в котором находятся названия месяцев, диву с названием текущего месяца присвоить отдельный класс, а не просто сменить цвет текста на red...

Добавлено через 13 минут
строка 535
JavaScript
1
document.querySelector(`#${name}`).style.backgroundColor = "#90EE90";
тут просто изменить на другой класс, например "cur_name_month"

а стиль применить не сложно...

проще говоря, не стиль менять, а присвоить отдельный класс...

названию дня недели и числу меняется через псевдоклассы, будни и выходные по разному, (n+6) красным, а будням синий разные оттенки...
0
 Аватар для Tavashi
1172 / 762 / 194
Регистрация: 21.05.2016
Сообщений: 1,858
29.05.2021, 07:04
PHP/HTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <style>
      @import url('https://fonts.googleapis.com/css?family=Baumans&display=swap');
 
      body {
        width: 1023px;
      }
 
      body,
      select,
      input {
        font: 14px serif;
      }
 
      #calendar {
        width: 330px;
        height: 375px;
        display: inline-block;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
 
      #navigation_panel {
        background-color: hsl(210, 100%, 92%);
        min-height: 34px;
        max-height: 78px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
        padding: 10px;
        margin-bottom: 5px;
        text-align: center;
        vertical-align: middle;
        display: -webkit-box;
        display: -webkit-flex;
        display: flex;
        -webkit-box-align: center;
        -webkit-align-items: center;
        align-items: center;
        -webkit-box-pack: center;
        -webkit-justify-content: center;
        justify-content: center;
        -webkit-flex-wrap: wrap;
        flex-wrap: wrap;
      }
 
      #navigation_panel button,
      #navigation_panel #calendar_year {
        background-color: hsl(210, 100%, 85%);
        color: hsl(210, 100%, 45%);
        font: 14px serif;
        border: 1px solid hsl(210, 100%, 45%);
      }
 
      #calendar_month {
        background-color: transparent;
        color: hsl(210, 100%, 45%);
        font: 14px serif;
        border: 1px solid hsl(210, 100%, 45%);
      }
 
      #navigation_panel button {
        height: 34px;
        vertical-align: middle;
      }
 
      #background_month {
        background-color: hsl(210, 100%, 85%);
        display: inline-block;
      }
 
      button.minus {
        width: 28px;
        text-align: center;
        border-radius: 12px 0 0 12px / 10px 0 0 10px;
        margin-right: -1px;
      }
 
      button.plus {
        width: 28px;
        text-align: center;
        border-radius: 0 12px 12px 0 / 0 10px 10px 0;
        margin-left: -1px;
      }
 
      .month_plus {
        margin-right: 35px;
      }
 
      .arrow {
        display: inline-block;
        line-height: 0.5;
      }
 
      #presently {
        width: 234px;
        margin-top: 10px;
        border-radius: 12px/10px;
      }
 
      #calendar_month {
        width: 89px;
        display: inline-block;
      }
 
      #calendar_year {
        width: 54px;
        display: inline-block;
      }
 
      select {
        height: 34px;
      }
 
      input {
        height: 30px;
        display: inline-block;
        text-align: center;
      }
 
      #table {
        font-family: 'Baumans', cursive;
        table-layout: fixed;
        width: 100%;
        height: 413px;
        padding: 2px;
      }
 
      #table,
      td {
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
      }
 
      td {
        margin: 1px;
        text-align: center;
      }
 
      #table tbody td.prevMonth {
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      }
 
      /* будние дни предыдущего месяца */
      #table tbody tr:nth-child(n + 6) td.prevMonth {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      }
 
      /* выходные дни предыдущего месяца */
      #table tbody td.nextMonth {
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      }
 
      /* будние дни следующего месяца */
      #table tbody tr:nth-child(n + 6) td.nextMonth {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      }
 
      /* выходные дни следующего месяца */
      #presently.hide {
        display: none;
      }
 
      #table tbody tr td.week-day {
        background-color: hsl(210, 100%, 85%);
        color: hsl(210, 100%, 50%);
        border: 1px solid hsl(0, 0%, 60%);
        width: 20%;
      }
 
      /* день недели */
      #table tbody tr:nth-child(n + 6) td.week-day {
        background-color: hsl(348, 100%, 85%);
        color: hsl(348, 100%, 50%);
        border: 1px solid hsl(0, 0%, 60%);
      }
 
      /* день недели выходной*/
      #table tbody tr td.week-day.curDay {
        border: 1px solid hsl(210, 100%, 50%);
        background-color: hsl(134, 100%, 50%); /**/
        color: hsl(210, 100%, 98%);
        font-weight: bold;
        text-shadow:
          1px 1px hsl(210, 100%, 50%),
          -1px 1px hsl(210, 100%, 50%),
          1px -1px hsl(210, 100%, 50%),
          -1px -1px hsl(210, 100%, 50%),
          1px 0 hsl(210, 100%, 50%),
          0 1px hsl(210, 100%, 50%),
          -1px 0 hsl(210, 100%, 50%),
          0 -1px hsl(210, 100%, 50%);
        letter-spacing: 2px;
      }
 
      /* сегодн день недели */
      #table tbody tr:nth-child(n + 6) td.week-day.curDay {
        border: 1px solid hsl(348, 100%, 50%);
        background-color: hsl(134, 100%, 50%); /**/
        color: hsl(348, 100%, 98%);
        font-weight: bold;
        text-shadow: 1px 1px hsl(348, 100%, 50%), 1px -1px hsl(348, 100%, 50%), -1px 1px hsl(348, 100%, 50%), -1px -1px hsl(348, 100%, 50%), 1px 0 hsl(348, 100%, 50%), -1px 0 hsl(348, 100%, 50%), 0 1px hsl(348, 100%, 50%), 0 -1px hsl(348, 100%, 50%);
        letter-spacing: 2px;
      }
 
      /* сегодн день недели выходной */
      #table tbody td {
        background-color: hsl(210, 100%, 90%);
        color: hsl(210, 100%, 50%);
      }
 
      /* будние дни текущего месяца */
      #table tbody tr:nth-child(n + 6) td {
        background-color: hsl(348, 100%, 90%);
        color: hsl(348, 100%, 50%);
      }
      
      /* выходные дни текущего месяца */
      #table tr td.curMonth.curDay {
        background-color: hsl(134, 100%, 50%); /**/
        border: 1px solid hsl(210, 100%, 50%);
        font-weight: bold;
        color: hsl(210, 100%, 100%);
        text-shadow: 1px 1px hsl(210, 100%, 50%), -1px 1px hsl(210, 100%, 50%), 1px -1px hsl(210, 100%, 50%), -1px -1px hsl(210, 100%, 50%), 1px 0 hsl(210, 100%, 50%), 0 1px hsl(210, 100%, 50%), -1px 0 hsl(210, 100%, 50%), 0 -1px hsl(210, 100%, 50%);
        letter-spacing: 3px;
      }
 
      /* сегодня будний */
      #table tr:nth-child(n + 6) td.curMonth.curDay {
        background-color: hsl(134, 100%, 50%); /**/
        border: 1px solid hsl(348, 100%, 50%);
        color: hsl(348, 100%, 100%);
        text-shadow: 1px 1px hsl(348, 100%, 50%), 1px -1px hsl(348, 100%, 50%), -1px 1px hsl(348, 100%, 50%), -1px -1px hsl(348, 100%, 50%), 1px 0 hsl(348, 100%, 50%), -1px 0 hsl(348, 100%, 50%), 0 1px hsl(348, 100%, 50%), 0 -1px hsl(348, 100%, 50%);
        letter-spacing: 3px;
      }
 
      /* сегодня выходной */
 
      #calendar {
        display: flex;
        flex-direction: column;
      }
 
      .content_month {
        flex: 1;
      }
 
      #table {
        height: 100%;
      }
 
      button,
      select,
      input {
        outline: none;
      }
      
      .td_month {
        width: 260px;
        height: 270px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
      }
 
      #num_year,
      #January,
      #February,
      #March,
      #April,
      #May,
      #June,
      #July,
      #August,
      #September,
      #October,
      #November,
      #December {
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 50%);
        font: bold 18px serif;
        text-align: center;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
 
      #num_year {
        font: bold 24px serif;
        width: auto;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
 
      #month1,
      #month2,
      #month3,
      #month4,
      #month5,
      #month6,
      #month7,
      #month8,
      #month9,
      #month10,
      #month11,
      #month12 {
        display: inline-block;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
        padding: 5px;
        width: auto;
      }
 
      .day {
        border: 1px solid hsl(0, 0%, 66%);
        width: auto;
        line-height: 30px;
        text-align: center;
        margin: 1px;
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 50%);
      }
 
      .table_month {
        table-layout: fixed;
        width: 100%;
        height: 220px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
      }
 
      .table_month tr td:nth-child(1) {
        width: 20%;
        font-weight: bold;
      }
 
      .table_month tr td.day:nth-child(1) {
        background-color: hsl(210, 100%, 88%);
        color: hsl(210, 100%, 60%);
      }
 
      .table_month tr:nth-child(n + 6) td.day:nth-child(1) {
        background-color: hsl(348, 100%, 88%);
        color: hsl(348, 100%, 60%);
      }
 
      .table_month tr:nth-child(n + 6) td.day {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 50%);
      }
 
      #year_input {
        border: 1px solid hsl(0, 0%, 66%);
        display: inline-block;
        text-align: center;
        font: bold 24px serif;
        color: hsl(210, 100%, 50%);
        width: 100px;
      }
      
      #January.someGreenClass,
      #February.someGreenClass,
      #March.someGreenClass,
      #April.someGreenClass,
      #May.someGreenClass,
      #June.someGreenClass,
      #July.someGreenClass,
      #August.someGreenClass,
      #September.someGreenClass,
      #October.someGreenClass,
      #November.someGreenClass,
      #December.someGreenClass {
        background-color: #90EE90;
        color: hsl(210, 100%, 50%);
        font: bold 18px serif;
        text-align: center;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
 
    </style>
  </head>
 
  <body>
    <div id="num_year">
      Календарь на
      <button class="year_minus"></button>
      <input id="year_input" type="number" size="4" value="2021" />
      <button class="year_plus"></button>
      год.<br />
      <button id="presently">сегодня</button>
    </div>
    <table id="table">
      <tr>
        <td class="td_month">
          <div id="month1">
            <div id="January"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month2">
            <div id="February"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month3">
            <div id="March"></div>
            <table class="table_month"></table>
          </div>
        </td>
      </tr>
      <tr>
        <td class="td_month">
          <div id="month4">
            <div id="April"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month5">
            <div id="May"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month6">
            <div id="June"></div>
            <table class="table_month"></table>
          </div>
        </td>
      </tr>
      <tr>
        <td class="td_month">
          <div id="month7">
            <div id="July"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month8">
            <div id="August"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month9">
            <div id="September"></div>
            <table class="table_month"></table>
          </div>
        </td>
      </tr>
      <tr>
        <td class="td_month">
          <div id="month10">
            <div id="October"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month11">
            <div id="November"></div>
            <table class="table_month"></table>
          </div>
        </td>
        <td class="td_month">
          <div id="month12">
            <div id="December"></div>
            <table class="table_month"></table>
          </div>
        </td>
      </tr>
    </table>
    <script>
      var calendar = {
        update: function(year, month) {
          this.year = year;
          this.month = ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'][month];
          var startDay = new Date(year, month, 1);
          var offsetDay = (startDay.getDay() || 7) - 1;
          startDay.setDate(startDay.getDate() - offsetDay);
          var lastDay = new Date(startDay);
          var days = new Date(year, month + 1, 0).getDate();
          days = Math.ceil((days + offsetDay) / 7) * 7;
          lastDay.setDate(lastDay.getDate() + days);
          this.data = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
          while (startDay < lastDay) {
            this.data.push(startDay.getDate());
            startDay.setHours(24);
          }
        },
        
        getCurDay: function(month, m, d, flag = false, flag2 = false) {
            let curDay;
            for (var i = 0; i < this.data.length; i++) {
            if (m === month) {
              if ((this.data[i] === 1 && flag) || flag2) {
                flag2 = true;
                continue;
              }
              if (this.data[i] === 1 || flag) {
                if (this.data[i] === d) curDay = i % 7;
                flag = true;
                continue;
              }
            }
          }
          return curDay;
        }, 
        
        render: function(month, name) {
          var html = ['<tr>', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>'];
          let m = new Date().getMonth(),
            d = new Date().getDate(),
            flag = false,
            flag2 = false,
            curDay = this.getCurDay(month, m, d),
            className;
          
          for (var i = 0; i < this.data.length; i++) {
            if (i >= 0 && i <= 6) {
                if (i === curDay) html[i % 7] += '<td class="week-day curDay">' + this.data[i];
              else html[i % 7] += '<td class="week-day">' + this.data[i];
              continue;
            }
             
              if ((this.data[i] === 1 && flag) || flag2) {
                flag2 = true;
                className = "prevMonth";
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              }
              
              if (this.data[i] === 1 || flag) {
                className = "curMonth";
                if (this.data[i] === d && m === month) {
                  className += " curDay";
                  document.querySelector(`#${name}`).classList.add('someGreenClass');
                }
                flag = true;
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              } else {
                className = "prevMonth";
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              }
              
              html[i % 7] += '<td class="prevMonth">' + this.data[i];
          }
          
          this.monthName.textContent = this.month;
          this.element.innerHTML = html.join('');
        }
      };
      
      var today = new Date(),
        thisYear = today.getFullYear(),
        thisMonth = today.getMonth(),
        months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
        year_minus = document.querySelector('.year_minus'),
        year_plus = document.querySelector('.year_plus'),
        buttonToday = document.querySelector('#presently'),
        yearListener = document.querySelector('#year_input');
 
      function make(year = thisYear) {
        months.forEach((v, i) => {
          calendar.monthName = document.querySelector(`#${v}`);
          calendar.element = document.querySelectorAll('.table_month')[i];
          calendar.update(year, i);
          calendar.render(i, months[i]);
        });
      };
      make();
      buttonToday.classList.add('hide');
    
      year_plus.addEventListener('click', function() {
        yearListener.value = ++thisYear;
        if (yearListener.value == today.getFullYear()) buttonToday.classList.add('hide')
        else buttonToday.classList.remove('hide');
        make(thisYear);
      });
 
      year_minus.addEventListener('click', function() {
        yearListener.value = --thisYear;
        if (yearListener.value == today.getFullYear()) buttonToday.classList.add('hide')
        else buttonToday.classList.remove('hide');
        make(thisYear);
      });
      
      buttonToday.addEventListener('click', function() {
        thisYear = today.getFullYear();
        yearListener.value = thisYear;
        make(thisYear);
        buttonToday.classList.add('hide');
      });
      
      yearListener.addEventListener('change', function() {
        thisYear = yearListener.value;
        if (yearListener.value == today.getFullYear()) buttonToday.classList.add('hide')
        else buttonToday.classList.remove('hide');
        make(+yearListener.value);
      });
      
    </script>
  </body>
</html>
0
 Аватар для Блондинка йа
13 / 12 / 1
Регистрация: 08.03.2019
Сообщений: 279
29.05.2021, 07:06  [ТС]
сейчас
HTML5
1
2
3
4
5
6
<td class="td_month">
          <div id="month5">
            <div id="May"></div>
            <table class="table_month"></table>
          </div>
        </td>
а надо
HTML5
1
2
3
4
5
6
<td class="td_month">
          <div id="cur_month_name">
            <div id="May"></div>
            <table class="table_month"></table>
          </div>
        </td>
0
 Аватар для Tavashi
1172 / 762 / 194
Регистрация: 21.05.2016
Сообщений: 1,858
29.05.2021, 07:30
HTML5
1
2
<div id="cur_month_name">
            <div id="May"></div>
May и есть cur_month_name.

Добавлено через 17 минут
<div id="month (1...12)"> можно удалить, эти стили уже не нужны:
PHP/HTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <style>
      @import url('https://fonts.googleapis.com/css?family=Baumans&display=swap');
 
      body {
        width: 1023px;
      }
 
      body,
      select,
      input {
        font: 14px serif;
      }
 
      #calendar {
        width: 330px;
        height: 375px;
        display: inline-block;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
 
      #navigation_panel {
        background-color: hsl(210, 100%, 92%);
        min-height: 34px;
        max-height: 78px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
        padding: 10px;
        margin-bottom: 5px;
        text-align: center;
        vertical-align: middle;
        display: -webkit-box;
        display: -webkit-flex;
        display: flex;
        -webkit-box-align: center;
        -webkit-align-items: center;
        align-items: center;
        -webkit-box-pack: center;
        -webkit-justify-content: center;
        justify-content: center;
        -webkit-flex-wrap: wrap;
        flex-wrap: wrap;
      }
 
      #navigation_panel button,
      #navigation_panel #calendar_year {
        background-color: hsl(210, 100%, 85%);
        color: hsl(210, 100%, 45%);
        font: 14px serif;
        border: 1px solid hsl(210, 100%, 45%);
      }
 
      #calendar_month {
        background-color: transparent;
        color: hsl(210, 100%, 45%);
        font: 14px serif;
        border: 1px solid hsl(210, 100%, 45%);
      }
 
      #navigation_panel button {
        height: 34px;
        vertical-align: middle;
      }
 
      #background_month {
        background-color: hsl(210, 100%, 85%);
        display: inline-block;
      }
 
      button.minus {
        width: 28px;
        text-align: center;
        border-radius: 12px 0 0 12px / 10px 0 0 10px;
        margin-right: -1px;
      }
 
      button.plus {
        width: 28px;
        text-align: center;
        border-radius: 0 12px 12px 0 / 0 10px 10px 0;
        margin-left: -1px;
      }
 
      .month_plus {
        margin-right: 35px;
      }
 
      .arrow {
        display: inline-block;
        line-height: 0.5;
      }
 
      #presently {
        width: 234px;
        margin-top: 10px;
        border-radius: 12px/10px;
      }
 
      #calendar_month {
        width: 89px;
        display: inline-block;
      }
 
      #calendar_year {
        width: 54px;
        display: inline-block;
      }
 
      select {
        height: 34px;
      }
 
      input {
        height: 30px;
        display: inline-block;
        text-align: center;
      }
 
      #table {
        font-family: 'Baumans', cursive;
        table-layout: fixed;
        width: 100%;
        height: 413px;
        padding: 2px;
      }
 
      #table,
      td {
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
      }
 
      td {
        margin: 1px;
        text-align: center;
      }
 
      #table tbody td.prevMonth {
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      }
 
      /* будние дни предыдущего месяца */
      #table tbody tr:nth-child(n + 6) td.prevMonth {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      }
 
      /* выходные дни предыдущего месяца */
      #table tbody td.nextMonth {
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      }
 
      /* будние дни следующего месяца */
      #table tbody tr:nth-child(n + 6) td.nextMonth {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      }
 
      /* выходные дни следующего месяца */
      #presently.hide {
        display: none;
      }
 
      #table tbody tr td.week-day {
        background-color: hsl(210, 100%, 85%);
        color: hsl(210, 100%, 50%);
        border: 1px solid hsl(0, 0%, 60%);
        width: 20%;
      }
 
      /* день недели */
      #table tbody tr:nth-child(n + 6) td.week-day {
        background-color: hsl(348, 100%, 85%);
        color: hsl(348, 100%, 50%);
        border: 1px solid hsl(0, 0%, 60%);
      }
 
      /* день недели выходной*/
      #table tbody tr td.week-day.curDay {
        border: 1px solid hsl(210, 100%, 50%);
        background-color: hsl(134, 100%, 50%); /**/
        color: hsl(210, 100%, 98%);
        font-weight: bold;
        text-shadow:
          1px 1px hsl(210, 100%, 50%),
          -1px 1px hsl(210, 100%, 50%),
          1px -1px hsl(210, 100%, 50%),
          -1px -1px hsl(210, 100%, 50%),
          1px 0 hsl(210, 100%, 50%),
          0 1px hsl(210, 100%, 50%),
          -1px 0 hsl(210, 100%, 50%),
          0 -1px hsl(210, 100%, 50%);
        letter-spacing: 2px;
      }
 
      /* сегодн день недели */
      #table tbody tr:nth-child(n + 6) td.week-day.curDay {
        border: 1px solid hsl(348, 100%, 50%);
        background-color: hsl(134, 100%, 50%); /**/
        color: hsl(348, 100%, 98%);
        font-weight: bold;
        text-shadow: 1px 1px hsl(348, 100%, 50%), 1px -1px hsl(348, 100%, 50%), -1px 1px hsl(348, 100%, 50%), -1px -1px hsl(348, 100%, 50%), 1px 0 hsl(348, 100%, 50%), -1px 0 hsl(348, 100%, 50%), 0 1px hsl(348, 100%, 50%), 0 -1px hsl(348, 100%, 50%);
        letter-spacing: 2px;
      }
 
      /* сегодн день недели выходной */
      #table tbody td {
        background-color: hsl(210, 100%, 90%);
        color: hsl(210, 100%, 50%);
      }
 
      /* будние дни текущего месяца */
      #table tbody tr:nth-child(n + 6) td {
        background-color: hsl(348, 100%, 90%);
        color: hsl(348, 100%, 50%);
      }
      
      /* выходные дни текущего месяца */
      #table tr td.curMonth.curDay {
        background-color: hsl(134, 100%, 50%); /**/
        border: 1px solid hsl(210, 100%, 50%);
        font-weight: bold;
        color: hsl(210, 100%, 100%);
        text-shadow: 1px 1px hsl(210, 100%, 50%), -1px 1px hsl(210, 100%, 50%), 1px -1px hsl(210, 100%, 50%), -1px -1px hsl(210, 100%, 50%), 1px 0 hsl(210, 100%, 50%), 0 1px hsl(210, 100%, 50%), -1px 0 hsl(210, 100%, 50%), 0 -1px hsl(210, 100%, 50%);
        letter-spacing: 3px;
      }
 
      /* сегодня будний */
      #table tr:nth-child(n + 6) td.curMonth.curDay {
        background-color: hsl(134, 100%, 50%); /**/
        border: 1px solid hsl(348, 100%, 50%);
        color: hsl(348, 100%, 100%);
        text-shadow: 1px 1px hsl(348, 100%, 50%), 1px -1px hsl(348, 100%, 50%), -1px 1px hsl(348, 100%, 50%), -1px -1px hsl(348, 100%, 50%), 1px 0 hsl(348, 100%, 50%), -1px 0 hsl(348, 100%, 50%), 0 1px hsl(348, 100%, 50%), 0 -1px hsl(348, 100%, 50%);
        letter-spacing: 3px;
      }
 
      /* сегодня выходной */
 
      #calendar {
        display: flex;
        flex-direction: column;
      }
 
      .content_month {
        flex: 1;
      }
 
      #table {
        height: 100%;
      }
 
      button,
      select,
      input {
        outline: none;
      }
      
      .td_month {
        width: 260px;
        height: 270px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
      }
 
      #num_year,
      #January,
      #February,
      #March,
      #April,
      #May,
      #June,
      #July,
      #August,
      #September,
      #October,
      #November,
      #December {
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 50%);
        font: bold 18px serif;
        text-align: center;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
 
      #num_year {
        font: bold 24px serif;
        width: auto;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
 
      .day {
        border: 1px solid hsl(0, 0%, 66%);
        width: auto;
        line-height: 30px;
        text-align: center;
        margin: 1px;
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 50%);
      }
 
      .table_month {
        table-layout: fixed;
        width: 100%;
        height: 220px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
      }
 
      .table_month tr td:nth-child(1) {
        width: 20%;
        font-weight: bold;
      }
 
      .table_month tr td.day:nth-child(1) {
        background-color: hsl(210, 100%, 88%);
        color: hsl(210, 100%, 60%);
      }
 
      .table_month tr:nth-child(n + 6) td.day:nth-child(1) {
        background-color: hsl(348, 100%, 88%);
        color: hsl(348, 100%, 60%);
      }
 
      .table_month tr:nth-child(n + 6) td.day {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 50%);
      }
 
      #year_input {
        border: 1px solid hsl(0, 0%, 66%);
        display: inline-block;
        text-align: center;
        font: bold 24px serif;
        color: hsl(210, 100%, 50%);
        width: 100px;
      }
      
      #January.someGreenClass,
      #February.someGreenClass,
      #March.someGreenClass,
      #April.someGreenClass,
      #May.someGreenClass,
      #June.someGreenClass,
      #July.someGreenClass,
      #August.someGreenClass,
      #September.someGreenClass,
      #October.someGreenClass,
      #November.someGreenClass,
      #December.someGreenClass {
        background-color: #90EE90;
        color: hsl(210, 100%, 50%);
        font: bold 18px serif;
        text-align: center;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
 
    </style>
  </head>
 
  <body>
    <div id="num_year">
      Календарь на
      <button class="year_minus"></button>
      <input id="year_input" type="number" size="4" value="2021" />
      <button class="year_plus"></button>
      год.<br />
      <button id="presently">сегодня</button>
    </div>
    <table id="table">
      <tr>
        <td class="td_month">
            <div id="January"></div>
            <table class="table_month"></table>
        </td>
        <td class="td_month">
            <div id="February"></div>
            <table class="table_month"></table>
        </td>
        <td class="td_month">
            <div id="March"></div>
            <table class="table_month"></table>
        </td>
      </tr>
      <tr>
        <td class="td_month">
            <div id="April"></div>
            <table class="table_month"></table>
        </td>
        <td class="td_month">
            <div id="May"></div>
            <table class="table_month"></table>
        </td>
        <td class="td_month">
            <div id="June"></div>
            <table class="table_month"></table>
        </td>
      </tr>
      <tr>
        <td class="td_month">
            <div id="July"></div>
            <table class="table_month"></table>
        </td>
        <td class="td_month">
            <div id="August"></div>
            <table class="table_month"></table>
        </td>
        <td class="td_month">
            <div id="September"></div>
            <table class="table_month"></table>
        </td>
      </tr>
      <tr>
        <td class="td_month">
            <div id="October"></div>
            <table class="table_month"></table>
        </td>
        <td class="td_month">
            <div id="November"></div>
            <table class="table_month"></table>
        </td>
        <td class="td_month">
            <div id="December"></div>
            <table class="table_month"></table>
        </td>
      </tr>
    </table>
    <script>
      var calendar = {
        update: function(year, month) {
          this.year = year;
          this.month = ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'][month];
          var startDay = new Date(year, month, 1);
          var offsetDay = (startDay.getDay() || 7) - 1;
          startDay.setDate(startDay.getDate() - offsetDay);
          var lastDay = new Date(startDay);
          var days = new Date(year, month + 1, 0).getDate();
          days = Math.ceil((days + offsetDay) / 7) * 7;
          lastDay.setDate(lastDay.getDate() + days);
          this.data = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
          while (startDay < lastDay) {
            this.data.push(startDay.getDate());
            startDay.setHours(24);
          }
        },
        
        getCurDay: function(month, m, d, flag = false, flag2 = false) {
            let curDay;
            for (var i = 0; i < this.data.length; i++) {
            if (m === month) {
              if ((this.data[i] === 1 && flag) || flag2) {
                flag2 = true;
                continue;
              }
              if (this.data[i] === 1 || flag) {
                if (this.data[i] === d) curDay = i % 7;
                flag = true;
                continue;
              }
            }
          }
          return curDay;
        }, 
        
        render: function(month, name) {
          var html = ['<tr>', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>'];
          let m = new Date().getMonth(),
            d = new Date().getDate(),
            flag = false,
            flag2 = false,
            curDay = this.getCurDay(month, m, d),
            className;
          
          for (var i = 0; i < this.data.length; i++) {
            if (i >= 0 && i <= 6) {
                if (i === curDay) html[i % 7] += '<td class="week-day curDay">' + this.data[i];
              else html[i % 7] += '<td class="week-day">' + this.data[i];
              continue;
            }
             
              if ((this.data[i] === 1 && flag) || flag2) {
                flag2 = true;
                className = "prevMonth";
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              }
              
              if (this.data[i] === 1 || flag) {
                className = "curMonth";
                if (this.data[i] === d && m === month) {
                  className += " curDay";
                  document.querySelector(`#${name}`).classList.add('someGreenClass');
                }
                flag = true;
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              } else {
                className = "prevMonth";
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              }
              
              html[i % 7] += '<td class="prevMonth">' + this.data[i];
          }
          
          this.monthName.textContent = this.month;
          this.element.innerHTML = html.join('');
        }
      };
      
      var today = new Date(),
        thisYear = today.getFullYear(),
        thisMonth = today.getMonth(),
        months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
        year_minus = document.querySelector('.year_minus'),
        year_plus = document.querySelector('.year_plus'),
        buttonToday = document.querySelector('#presently'),
        yearListener = document.querySelector('#year_input');
 
      function make(year = thisYear) {
        months.forEach((v, i) => {
          calendar.monthName = document.querySelector(`#${v}`);
          calendar.element = document.querySelectorAll('.table_month')[i];
          calendar.update(year, i);
          calendar.render(i, months[i]);
        });
      };
      make();
      buttonToday.classList.add('hide');
    
      year_plus.addEventListener('click', function() {
        yearListener.value = ++thisYear;
        if (yearListener.value == today.getFullYear()) buttonToday.classList.add('hide')
        else buttonToday.classList.remove('hide');
        make(thisYear);
      });
 
      year_minus.addEventListener('click', function() {
        yearListener.value = --thisYear;
        if (yearListener.value == today.getFullYear()) buttonToday.classList.add('hide')
        else buttonToday.classList.remove('hide');
        make(thisYear);
      });
      
      buttonToday.addEventListener('click', function() {
        thisYear = today.getFullYear();
        yearListener.value = thisYear;
        make(thisYear);
        buttonToday.classList.add('hide');
      });
      
      yearListener.addEventListener('change', function() {
        thisYear = yearListener.value;
        if (yearListener.value == today.getFullYear()) buttonToday.classList.add('hide')
        else buttonToday.classList.remove('hide');
        make(+yearListener.value);
      });
      
    </script>
  </body>
</html>
0
 Аватар для Блондинка йа
13 / 12 / 1
Регистрация: 08.03.2019
Сообщений: 279
29.05.2021, 19:22  [ТС]
немного повозилась со стилями, чтобы было понятнее

результат
PHP/HTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <style>
      @import url('https://fonts.googleapis.com/css?family=Baumans&display=swap');
 
      body {
        width: 860px;
      }
 
      body,
      select,
      input {
        font: 14px serif;
      }
 
      #calendar {
        width: 330px;
        height: 375px;
        display: inline-block;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
 
      #navigation_panel {
        background-color: hsl(210, 100%, 92%);
        min-height: 34px;
        max-height: 78px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
        padding: 10px;
        margin-bottom: 5px;
        text-align: center;
        vertical-align: middle;
        display: -webkit-box;
        display: -webkit-flex;
        display: flex;
        -webkit-box-align: center;
        -webkit-align-items: center;
        align-items: center;
        -webkit-box-pack: center;
        -webkit-justify-content: center;
        justify-content: center;
        -webkit-flex-wrap: wrap;
        flex-wrap: wrap;
      }
 
      #navigation_panel button,
      #navigation_panel #calendar_year {
        background-color: hsl(210, 100%, 85%);
        color: hsl(210, 100%, 45%);
        font: 14px serif;
        border: 1px solid hsl(210, 100%, 45%);
      }
      
      button.year_minus,
      button.year_plus {
      background-color: hsl(210, 100%, 75%);
      color: hsl(210, 100%, 45%);
      font: 24px serif;
      border: 1px solid hsl(210, 100%, 45%);
      width: 55px;
      height: 52px;
      position: relative; top: 2px;
      }
 
      button.year_minus {
      margin-right: -9.5px;
      border-radius: 32px 0 0 32px / 20px 0 0 20px;
      }
      
      button.year_plus {
      margin-left: -9px;
      border-radius: 0 32px 32px 0 / 0 20px 20px 0;
      }
      
      #calendar_month {
        background-color: transparent;
        color: hsl(210, 100%, 45%);
        font: 14px serif;
        border: 1px solid hsl(210, 100%, 45%);
      }
 
      #navigation_panel button {
        height: 34px;
        vertical-align: middle;
      }
 
      #background_month {
        background-color: hsl(210, 100%, 85%);
        display: inline-block;
      }
 
      button.minus {
        width: 28px;
        text-align: center;
        border-radius: 12px 0 0 12px / 10px 0 0 10px;
        margin-right: -1px;
      }
 
      button.plus {
        width: 28px;
        text-align: center;
        border-radius: 0 12px 12px 0 / 0 10px 10px 0;
        margin-left: -1px;
      }
 
      .month_plus {
        margin-right: 35px;
      }
 
      .arrow {
        display: inline-block;
        line-height: 0.5;
      }
 
      #presently {
        background-color: hsl(210, 100%, 90%);
        color: hsl(210, 100%, 45%);
        font: 24px serif;
        border: 1px solid hsl(210, 100%, 45%);
        width: 540px;
        height: 52px;
        
        
 
        margin-top: 10px;
        border-radius: 32px/20px;
      }
 
      #calendar_month {
        width: 89px;
        display: inline-block;
      }
 
      #calendar_year {
        width: 54px;
        display: inline-block;
      }
 
      select {
        height: 34px;
      }
 
      input {
        height: 30px;
        display: inline-block;
        text-align: center;
      }
 
      #table {
        font-family: 'Baumans', cursive;
        table-layout: fixed;
        width: 100%;
        height: 413px;
        padding: 2px;
      }
 
      #table,
      td {
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
      }
 
      td {
        margin: 1px;
        text-align: center;
      }
 
      #table tbody td.prevMonth {
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      } /* будние дни предыдущего месяца */
      
      #table tbody tr:nth-child(n + 6) td.prevMonth {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      } /* выходные дни предыдущего месяца */
      
      #table tbody td.nextMonth {
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      } /* будние дни следующего месяца */
      
      #table tbody tr:nth-child(n + 6) td.nextMonth {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      } /* выходные дни следующего месяца */
      
      #presently.hide {
        display: none;
      }
 
      #table tbody tr td.week-day {
        background-color: hsl(210, 100%, 85%);
        color: hsl(210, 100%, 50%);
        border: 1px solid hsl(0, 0%, 60%);
        width: 20%;
      } /* день недели */
      
      #table tbody tr:nth-child(n + 6) td.week-day {
        background-color: hsl(348, 100%, 85%);
        color: hsl(348, 100%, 50%);
        border: 1px solid hsl(0, 0%, 60%);
      } /* день недели выходной*/
      
      #table tbody tr td.week-day.curDay {
        border: 1px solid hsl(210, 100%, 50%);
        background-color: hsl(210, 100%, 70%); /**/
        color: hsl(210, 100%, 98%);
        font-weight: bold;
        text-shadow:
          1px 1px hsl(210, 100%, 50%),
          -1px 1px hsl(210, 100%, 50%),
          1px -1px hsl(210, 100%, 50%),
          -1px -1px hsl(210, 100%, 50%),
          1px 0 hsl(210, 100%, 50%),
          0 1px hsl(210, 100%, 50%),
          -1px 0 hsl(210, 100%, 50%),
          0 -1px hsl(210, 100%, 50%);
        letter-spacing: 2px;
      } /* сегодн день недели */
      
      #table tbody tr:nth-child(n + 6) td.week-day.curDay {
        border: 1px solid hsl(348, 100%, 50%);
        background-color: hsl(348, 100%, 75%); /**/
        color: hsl(348, 100%, 98%);
        font-weight: bold;
        text-shadow: 1px 1px hsl(348, 100%, 50%), 1px -1px hsl(348, 100%, 50%), -1px 1px hsl(348, 100%, 50%), -1px -1px hsl(348, 100%, 50%), 1px 0 hsl(348, 100%, 50%), -1px 0 hsl(348, 100%, 50%), 0 1px hsl(348, 100%, 50%), 0 -1px hsl(348, 100%, 50%);
        letter-spacing: 2px;
      } /* сегодн день недели выходной */
      
      #table tbody td {
        background-color: hsl(210, 100%, 90%);
        color: hsl(210, 100%, 50%);
      } /* будние дни текущего месяца */
      
      #table tbody tr:nth-child(n + 6) td {
        background-color: hsl(348, 100%, 90%);
        color: hsl(348, 100%, 50%);
      } /* выходные дни текущего месяца */
      
      #table tr td.curMonth.curDay {
        background-color: hsl(210, 100%, 75%); /**/
        border: 1px solid hsl(210, 100%, 50%);
        font-weight: bold;
        color: hsl(210, 100%, 100%);
        text-shadow: 1px 1px hsl(210, 100%, 50%), -1px 1px hsl(210, 100%, 50%), 1px -1px hsl(210, 100%, 50%), -1px -1px hsl(210, 100%, 50%), 1px 0 hsl(210, 100%, 50%), 0 1px hsl(210, 100%, 50%), -1px 0 hsl(210, 100%, 50%), 0 -1px hsl(210, 100%, 50%);
        letter-spacing: 3px;
      } /* сегодня будний */
      
      #table tr:nth-child(n + 6) td.curMonth.curDay {
        background-color: hsl(348, 100%, 75%); /**/
        border: 1px solid hsl(348, 100%, 50%);
        color: hsl(348, 100%, 100%);
        text-shadow: 1px 1px hsl(348, 100%, 50%), 1px -1px hsl(348, 100%, 50%), -1px 1px hsl(348, 100%, 50%), -1px -1px hsl(348, 100%, 50%), 1px 0 hsl(348, 100%, 50%), -1px 0 hsl(348, 100%, 50%), 0 1px hsl(348, 100%, 50%), 0 -1px hsl(348, 100%, 50%);
        letter-spacing: 3px;
      } /* сегодня выходной */
 
      #calendar {
        display: flex;
        flex-direction: column;
      }
 
      .content_month {
        flex: 1;
      }
 
      #table {
        height: 100%;
      }
 
      button,
      select,
      input {
        outline: none;
      }
      
      .td_month {
        width: 200px;
        height: 290px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
      }
 
      #January,
      #February,
      #March,
      #April,
      #May,
      #June,
      #July,
      #August,
      #September,
      #October,
      #November,
      #December {
        background-color: hsl(210, 100%, 86%);
        color: hsl(210, 100%, 50%);
        font: bold 18px serif;
        text-align: center;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
      
      #num_year {
        font: bold 24px serif;
        width: auto;
        padding: 5px;
        background-color: hsl(210, 100%, 86%);
        color: hsl(210, 100%, 50%);
        border: 1px solid hsl(0, 0%, 66%);
        text-align: center;
        padding: 10px;
        margin: 0 0 5px 0;
        border-radius: 8px;
      }
 
      .day {
        border: 1px solid hsl(0, 0%, 66%);
        width: auto;
        line-height: 30px;
        text-align: center;
        margin: 1px;
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 50%);
      }
 
      .table_month {
        table-layout: fixed;
        width: 100%;
        height: 320px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
      }
 
      .table_month tr td:nth-child(1) {
        width: 20%;
        font-weight: bold;
      }
 
      .table_month tr td.day:nth-child(1) {
        background-color: hsl(210, 100%, 86%);
        color: hsl(210, 100%, 50%);
      } /* названия дней недели будни */
 
      .table_month tr:nth-child(n + 6) td.day:nth-child(1) {
        background-color: hsl(348, 100%, 86%);
        color: hsl(348, 100%, 50%);
      } /* названия дней недели выходные */
 
      .table_month tr:nth-child(n + 6) td.day {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 50%);
      }
 
      #year_input {
        background-color: hsl(210, 100%, 90%);
        color: hsl(210, 100%, 50%);
        border: 1px solid hsl(210, 100%, 50%);
        display: inline-block;
        text-align: center;
        font: bold 24px serif;
        width: 100px;
        padding: 10px;
      }
      
      #January.cur_month_name,
      #February.cur_month_name,
      #March.cur_month_name,
      #April.cur_month_name,
      #May.cur_month_name,
      #June.cur_month_name,
      #July.cur_month_name,
      #August.cur_month_name,
      #September.cur_month_name,
      #October.cur_month_name,
      #November.cur_month_name,
      #December.cur_month_name {
        background-color: hsl(210, 100%, 70%);
        color: hsl(210, 100%, 98%);
        font: bold 18px serif;
        text-align: center;
        border: 1px solid hsl(210, 100%, 50%);
        border-radius: 4px;
        padding: 5px;
        margin: 0 0 5px 0;
        text-shadow:
        1px 1px hsl(210, 100%, 50%),
        -1px 1px hsl(210, 100%, 50%),
        1px -1px hsl(210, 100%, 50%),
        -1px -1px hsl(210, 100%, 50%),
        1px 0 hsl(210, 100%, 50%),
        0 1px hsl(210, 100%, 50%),
        -1px 0 hsl(210, 100%, 50%),
        0 -1px hsl(210, 100%, 50%);
        letter-spacing: 2px;
      } /* название текущего месяца */
 
    </style>
  </head>
 
  <body>
    <div id="num_year">
      Календарь на
      <button class="year_minus"></button>
      <input id="year_input" type="number" size="4" value="2012" />
      <button class="year_plus"></button>
      год.<br />
      <button id="presently">сегодня</button>
    </div>
    <table id="table">
      <tr>
        <td class="td_month">
            <div id="January"></div>
            <table class="table_month"></table>
        </td>
        <td class="td_month">
            <div id="February"></div>
            <table class="table_month"></table>
        </td>
        <td class="td_month">
            <div id="March"></div>
            <table class="table_month"></table>
        </td>
      </tr>
      <tr>
        <td class="td_month">
            <div id="April"></div>
            <table class="table_month"></table>
        </td>
        <td class="td_month">
            <div id="May"></div>
            <table class="table_month"></table>
        </td>
        <td class="td_month">
            <div id="June"></div>
            <table class="table_month"></table>
        </td>
      </tr>
      <tr>
        <td class="td_month">
            <div id="July"></div>
            <table class="table_month"></table>
        </td>
        <td class="td_month">
            <div id="August"></div>
            <table class="table_month"></table>
        </td>
        <td class="td_month">
            <div id="September"></div>
            <table class="table_month"></table>
        </td>
      </tr>
      <tr>
        <td class="td_month">
            <div id="October"></div>
            <table class="table_month"></table>
        </td>
        <td class="td_month">
            <div id="November"></div>
            <table class="table_month"></table>
        </td>
        <td class="td_month">
            <div id="December"></div>
            <table class="table_month"></table>
        </td>
      </tr>
    </table>
    <script>
      var calendar = {
        update: function(year, month) {
          this.year = year;
          this.month = ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'][month];
          var startDay = new Date(year, month, 1);
          var offsetDay = (startDay.getDay() || 7) - 1;
          startDay.setDate(startDay.getDate() - offsetDay);
          var lastDay = new Date(startDay);
          var days = new Date(year, month + 1, 0).getDate();
          days = Math.ceil((days + offsetDay) / 7) * 7;
          lastDay.setDate(lastDay.getDate() + days);
          this.data = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
          while (startDay < lastDay) {
            this.data.push(startDay.getDate());
            startDay.setHours(24);
          }
        },
        
        getCurDay: function(month, m, d, flag = false, flag2 = false) {
            var curDay;
            for (var i = 0; i < this.data.length; i++) {
            if (m === month) {
              if ((this.data[i] === 1 && flag) || flag2) {
                flag2 = true;
                continue;
              }
              if (this.data[i] === 1 || flag) {
                if (this.data[i] === d) curDay = i % 7;
                flag = true;
                continue;
              }
            }
          }
          return curDay;
        }, 
        
        render: function(month, name) {
          var html = ['<tr>', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>'];
          var m = new Date().getMonth(),
            d = new Date().getDate(),
            flag = false,
            flag2 = false,
            curDay = this.getCurDay(month, m, d),
            className;
          
          for (var i = 0; i < this.data.length; i++) {
            if (i >= 0 && i <= 6) {
                if (i === curDay) html[i % 7] += '<td class="week-day curDay">' + this.data[i];
              else html[i % 7] += '<td class="week-day">' + this.data[i];
              continue;
            }
             
              if ((this.data[i] === 1 && flag) || flag2) {
                flag2 = true;
                className = "prevMonth";
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              }
              
              if (this.data[i] === 1 || flag) {
                className = "curMonth";
                if (this.data[i] === d && m === month) {
                  className += " curDay";
                  document.querySelector(`#${name}`).classList.add('cur_month_name');
                }
                flag = true;
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              } else {
                className = "prevMonth";
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              }
              
              html[i % 7] += '<td class="prevMonth">' + this.data[i];
          }
          
          this.monthName.textContent = this.month;
          this.element.innerHTML = html.join('');
        }
      };
      
      var today = new Date(),
        thisYear = today.getFullYear(),
        thisMonth = today.getMonth(),
        months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
        year_minus = document.querySelector('.year_minus'),
        year_plus = document.querySelector('.year_plus'),
        buttonToday = document.querySelector('#presently'),
        yearListener = document.querySelector('#year_input');
 
      function make(year = thisYear) {
        months.forEach((v, i) => {
          calendar.monthName = document.querySelector(`#${v}`);
          calendar.element = document.querySelectorAll('.table_month')[i];
          calendar.update(year, i);
          calendar.render(i, months[i]);
        });
      };
      make();
      buttonToday.classList.add('hide');
    
      year_plus.addEventListener('click', function() {
        yearListener.value = ++thisYear;
        if (yearListener.value == today.getFullYear()) buttonToday.classList.add('hide')
        else buttonToday.classList.remove('hide');
        make(thisYear);
      });
 
      year_minus.addEventListener('click', function() {
        yearListener.value = --thisYear;
        if (yearListener.value == today.getFullYear()) buttonToday.classList.add('hide')
        else buttonToday.classList.remove('hide');
        make(thisYear);
      });
      
      buttonToday.addEventListener('click', function() {
        thisYear = today.getFullYear();
        yearListener.value = thisYear;
        make(thisYear);
        buttonToday.classList.add('hide');
      });
      
      yearListener.addEventListener('change', function() {
        thisYear = yearListener.value;
        if (yearListener.value == today.getFullYear()) buttonToday.classList.add('hide')
        else buttonToday.classList.remove('hide');
        make(+yearListener.value);
      });
      
    </script>
  </body>
</html>
придётся ещё разбираться со стилями, но только ловить оттенок цветов, изменять только значения L в цветах HSL ...

Добавлено через 17 минут
как отследить событие oninput и при смене введённых символов чтобы календарь менял отображение года, а то до сих пор при потере фокуса у поля ввода ничего не происходит...

как заполнить поле ввода текущим годом, чтобы скрипт игнорировал значение value введённый в html и вставлял текущий год?

как добавить таймер, чтобы весь календарь обновлялся в полночь? а то если заходишь за пару минут до полуночи, подсветка не изменится пока не обновить страницу, а скрипт должен изменять цвет текущей даты автоматически в полночь, без обновления страницы...
0
 Аватар для Tavashi
1172 / 762 / 194
Регистрация: 21.05.2016
Сообщений: 1,858
30.05.2021, 01:35
Лучший ответ Сообщение было отмечено Блондинка йа как решение

Решение

Цитата Сообщение от Блондинка йа Посмотреть сообщение
как заполнить поле ввода текущим годом, чтобы скрипт игнорировал значение value введённый в html и вставлял текущий год?

как добавить таймер, чтобы весь календарь обновлялся в полночь? а то если заходишь за пару минут до полуночи, подсветка не изменится пока не обновить страницу, а скрипт должен изменять цвет текущей даты автоматически в полночь, без обновления страницы...
PHP/HTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <style>
      @import url('https://fonts.googleapis.com/css?family=Baumans&display=swap');
 
      body {
        width: 860px;
      }
 
      body,
      select,
      input {
        font: 14px serif;
      }
 
      #calendar {
        width: 330px;
        height: 375px;
        display: inline-block;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
 
      #navigation_panel {
        background-color: hsl(210, 100%, 92%);
        min-height: 34px;
        max-height: 78px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
        padding: 10px;
        margin-bottom: 5px;
        text-align: center;
        vertical-align: middle;
        display: -webkit-box;
        display: -webkit-flex;
        display: flex;
        -webkit-box-align: center;
        -webkit-align-items: center;
        align-items: center;
        -webkit-box-pack: center;
        -webkit-justify-content: center;
        justify-content: center;
        -webkit-flex-wrap: wrap;
        flex-wrap: wrap;
      }
 
      #navigation_panel button,
      #navigation_panel #calendar_year {
        background-color: hsl(210, 100%, 85%);
        color: hsl(210, 100%, 45%);
        font: 14px serif;
        border: 1px solid hsl(210, 100%, 45%);
      }
      
      button.year_minus,
      button.year_plus {
      background-color: hsl(210, 100%, 75%);
      color: hsl(210, 100%, 45%);
      font: 24px serif;
      border: 1px solid hsl(210, 100%, 45%);
      width: 55px;
      height: 52px;
      position: relative; top: 2px;
      }
 
      button.year_minus {
      margin-right: -9.5px;
      border-radius: 32px 0 0 32px / 20px 0 0 20px;
      }
      
      button.year_plus {
      margin-left: -9px;
      border-radius: 0 32px 32px 0 / 0 20px 20px 0;
      }
      
      #calendar_month {
        background-color: transparent;
        color: hsl(210, 100%, 45%);
        font: 14px serif;
        border: 1px solid hsl(210, 100%, 45%);
      }
 
      #navigation_panel button {
        height: 34px;
        vertical-align: middle;
      }
 
      #background_month {
        background-color: hsl(210, 100%, 85%);
        display: inline-block;
      }
 
      button.minus {
        width: 28px;
        text-align: center;
        border-radius: 12px 0 0 12px / 10px 0 0 10px;
        margin-right: -1px;
      }
 
      button.plus {
        width: 28px;
        text-align: center;
        border-radius: 0 12px 12px 0 / 0 10px 10px 0;
        margin-left: -1px;
      }
 
      .month_plus {
        margin-right: 35px;
      }
 
      .arrow {
        display: inline-block;
        line-height: 0.5;
      }
 
      #presently {
        background-color: hsl(210, 100%, 90%);
        color: hsl(210, 100%, 45%);
        font: 24px serif;
        border: 1px solid hsl(210, 100%, 45%);
        width: 540px;
        height: 52px;
        
        
 
        margin-top: 10px;
        border-radius: 32px/20px;
      }
 
      #calendar_month {
        width: 89px;
        display: inline-block;
      }
 
      #calendar_year {
        width: 54px;
        display: inline-block;
      }
 
      select {
        height: 34px;
      }
 
      input {
        height: 30px;
        display: inline-block;
        text-align: center;
      }
 
      #table {
        font-family: 'Baumans', cursive;
        table-layout: fixed;
        width: 100%;
        height: 413px;
        padding: 2px;
      }
 
      #table,
      td {
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
      }
 
      td {
        margin: 1px;
        text-align: center;
      }
 
      #table tbody td.prevMonth {
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      } /* будние дни предыдущего месяца */
      
      #table tbody tr:nth-child(n + 6) td.prevMonth {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      } /* выходные дни предыдущего месяца */
      
      #table tbody td.nextMonth {
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      } /* будние дни следующего месяца */
      
      #table tbody tr:nth-child(n + 6) td.nextMonth {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      } /* выходные дни следующего месяца */
      
      #presently.hide {
        display: none;
      }
 
      #table tbody tr td.week-day {
        background-color: hsl(210, 100%, 85%);
        color: hsl(210, 100%, 50%);
        border: 1px solid hsl(0, 0%, 60%);
        width: 20%;
      } /* день недели */
      
      #table tbody tr:nth-child(n + 6) td.week-day {
        background-color: hsl(348, 100%, 85%);
        color: hsl(348, 100%, 50%);
        border: 1px solid hsl(0, 0%, 60%);
      } /* день недели выходной*/
      
      #table tbody tr td.week-day.curDay {
        border: 1px solid hsl(210, 100%, 50%);
        background-color: hsl(210, 100%, 70%); /**/
        color: hsl(210, 100%, 98%);
        font-weight: bold;
        text-shadow:
          1px 1px hsl(210, 100%, 50%),
          -1px 1px hsl(210, 100%, 50%),
          1px -1px hsl(210, 100%, 50%),
          -1px -1px hsl(210, 100%, 50%),
          1px 0 hsl(210, 100%, 50%),
          0 1px hsl(210, 100%, 50%),
          -1px 0 hsl(210, 100%, 50%),
          0 -1px hsl(210, 100%, 50%);
        letter-spacing: 2px;
      } /* сегодн день недели */
      
      #table tbody tr:nth-child(n + 6) td.week-day.curDay {
        border: 1px solid hsl(348, 100%, 50%);
        background-color: hsl(348, 100%, 75%); /**/
        color: hsl(348, 100%, 98%);
        font-weight: bold;
        text-shadow: 1px 1px hsl(348, 100%, 50%), 1px -1px hsl(348, 100%, 50%), -1px 1px hsl(348, 100%, 50%), -1px -1px hsl(348, 100%, 50%), 1px 0 hsl(348, 100%, 50%), -1px 0 hsl(348, 100%, 50%), 0 1px hsl(348, 100%, 50%), 0 -1px hsl(348, 100%, 50%);
        letter-spacing: 2px;
      } /* сегодн день недели выходной */
      
      #table tbody td {
        background-color: hsl(210, 100%, 90%);
        color: hsl(210, 100%, 50%);
      } /* будние дни текущего месяца */
      
      #table tbody tr:nth-child(n + 6) td {
        background-color: hsl(348, 100%, 90%);
        color: hsl(348, 100%, 50%);
      } /* выходные дни текущего месяца */
      
      #table tr td.curMonth.curDay {
        background-color: hsl(210, 100%, 75%); /**/
        border: 1px solid hsl(210, 100%, 50%);
        font-weight: bold;
        color: hsl(210, 100%, 100%);
        text-shadow: 1px 1px hsl(210, 100%, 50%), -1px 1px hsl(210, 100%, 50%), 1px -1px hsl(210, 100%, 50%), -1px -1px hsl(210, 100%, 50%), 1px 0 hsl(210, 100%, 50%), 0 1px hsl(210, 100%, 50%), -1px 0 hsl(210, 100%, 50%), 0 -1px hsl(210, 100%, 50%);
        letter-spacing: 3px;
      } /* сегодня будний */
      
      #table tr:nth-child(n + 6) td.curMonth.curDay {
        background-color: hsl(348, 100%, 75%); /**/
        border: 1px solid hsl(348, 100%, 50%);
        color: hsl(348, 100%, 100%);
        text-shadow: 1px 1px hsl(348, 100%, 50%), 1px -1px hsl(348, 100%, 50%), -1px 1px hsl(348, 100%, 50%), -1px -1px hsl(348, 100%, 50%), 1px 0 hsl(348, 100%, 50%), -1px 0 hsl(348, 100%, 50%), 0 1px hsl(348, 100%, 50%), 0 -1px hsl(348, 100%, 50%);
        letter-spacing: 3px;
      } /* сегодня выходной */
 
      #calendar {
        display: flex;
        flex-direction: column;
      }
 
      .content_month {
        flex: 1;
      }
 
      #table {
        height: 100%;
      }
 
      button,
      select,
      input {
        outline: none;
      }
      
      .td_month {
        width: 200px;
        height: 290px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
      }
 
      #January,
      #February,
      #March,
      #April,
      #May,
      #June,
      #July,
      #August,
      #September,
      #October,
      #November,
      #December {
        background-color: hsl(210, 100%, 86%);
        color: hsl(210, 100%, 50%);
        font: bold 18px serif;
        text-align: center;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
      
      #num_year {
        font: bold 24px serif;
        width: auto;
        padding: 5px;
        background-color: hsl(210, 100%, 86%);
        color: hsl(210, 100%, 50%);
        border: 1px solid hsl(0, 0%, 66%);
        text-align: center;
        padding: 10px;
        margin: 0 0 5px 0;
        border-radius: 8px;
      }
 
      .day {
        border: 1px solid hsl(0, 0%, 66%);
        width: auto;
        line-height: 30px;
        text-align: center;
        margin: 1px;
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 50%);
      }
 
      .table_month {
        table-layout: fixed;
        width: 100%;
        height: 320px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
      }
 
      .table_month tr td:nth-child(1) {
        width: 20%;
        font-weight: bold;
      }
 
      .table_month tr td.day:nth-child(1) {
        background-color: hsl(210, 100%, 86%);
        color: hsl(210, 100%, 50%);
      } /* названия дней недели будни */
 
      .table_month tr:nth-child(n + 6) td.day:nth-child(1) {
        background-color: hsl(348, 100%, 86%);
        color: hsl(348, 100%, 50%);
      } /* названия дней недели выходные */
 
      .table_month tr:nth-child(n + 6) td.day {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 50%);
      }
 
      #year_input {
        background-color: hsl(210, 100%, 90%);
        color: hsl(210, 100%, 50%);
        border: 1px solid hsl(210, 100%, 50%);
        display: inline-block;
        text-align: center;
        font: bold 24px serif;
        width: 100px;
        padding: 10px;
      }
      
      #January.cur_month_name,
      #February.cur_month_name,
      #March.cur_month_name,
      #April.cur_month_name,
      #May.cur_month_name,
      #June.cur_month_name,
      #July.cur_month_name,
      #August.cur_month_name,
      #September.cur_month_name,
      #October.cur_month_name,
      #November.cur_month_name,
      #December.cur_month_name {
        background-color: hsl(210, 100%, 70%);
        color: hsl(210, 100%, 98%);
        font: bold 18px serif;
        text-align: center;
        border: 1px solid hsl(210, 100%, 50%);
        border-radius: 4px;
        padding: 5px;
        margin: 0 0 5px 0;
        text-shadow:
        1px 1px hsl(210, 100%, 50%),
        -1px 1px hsl(210, 100%, 50%),
        1px -1px hsl(210, 100%, 50%),
        -1px -1px hsl(210, 100%, 50%),
        1px 0 hsl(210, 100%, 50%),
        0 1px hsl(210, 100%, 50%),
        -1px 0 hsl(210, 100%, 50%),
        0 -1px hsl(210, 100%, 50%);
        letter-spacing: 2px;
      } /* название текущего месяца */
 
    </style>
  </head>
 
  <body>
    <div id="num_year">
      Календарь на
      <button class="year_minus"></button>
      <input id="year_input" type="number" size="4" value="2012" />
      <button class="year_plus"></button>
      год.<br />
      <button id="presently">сегодня</button>
    </div>
    <table id="table">
      <tr>
        <td class="td_month">
            <div id="January"></div>
            <table class="table_month"></table>
        </td>
        <td class="td_month">
            <div id="February"></div>
            <table class="table_month"></table>
        </td>
        <td class="td_month">
            <div id="March"></div>
            <table class="table_month"></table>
        </td>
      </tr>
      <tr>
        <td class="td_month">
            <div id="April"></div>
            <table class="table_month"></table>
        </td>
        <td class="td_month">
            <div id="May"></div>
            <table class="table_month"></table>
        </td>
        <td class="td_month">
            <div id="June"></div>
            <table class="table_month"></table>
        </td>
      </tr>
      <tr>
        <td class="td_month">
            <div id="July"></div>
            <table class="table_month"></table>
        </td>
        <td class="td_month">
            <div id="August"></div>
            <table class="table_month"></table>
        </td>
        <td class="td_month">
            <div id="September"></div>
            <table class="table_month"></table>
        </td>
      </tr>
      <tr>
        <td class="td_month">
            <div id="October"></div>
            <table class="table_month"></table>
        </td>
        <td class="td_month">
            <div id="November"></div>
            <table class="table_month"></table>
        </td>
        <td class="td_month">
            <div id="December"></div>
            <table class="table_month"></table>
        </td>
      </tr>
    </table>
    <script>
      var calendar = {
        update: function(year, month) {
          this.year = year;
          this.month = ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'][month];
          var startDay = new Date(year, month, 1);
          var offsetDay = (startDay.getDay() || 7) - 1;
          startDay.setDate(startDay.getDate() - offsetDay);
          var lastDay = new Date(startDay);
          var days = new Date(year, month + 1, 0).getDate();
          days = Math.ceil((days + offsetDay) / 7) * 7;
          lastDay.setDate(lastDay.getDate() + days);
          this.data = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
          while (startDay < lastDay) {
            this.data.push(startDay.getDate());
            startDay.setHours(24);
          }
        },
        
        getCurDay: function(month, m, d, flag = false, flag2 = false) {
            var curDay;
            for (var i = 0; i < this.data.length; i++) {
            if (m === month) {
              if ((this.data[i] === 1 && flag) || flag2) {
                flag2 = true;
                continue;
              }
              if (this.data[i] === 1 || flag) {
                if (this.data[i] === d) curDay = i % 7;
                flag = true;
                continue;
              }
            }
          }
          return curDay;
        }, 
        
        render: function(month, name) {
          var html = ['<tr>', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>'];
          var m = new Date().getMonth(),
            d = new Date().getDate(),
            flag = false,
            flag2 = false,
            curDay = this.getCurDay(month, m, d),
            className;
          
          for (var i = 0; i < this.data.length; i++) {
            if (i >= 0 && i <= 6) {
                if (i === curDay) html[i % 7] += '<td class="week-day curDay">' + this.data[i];
              else html[i % 7] += '<td class="week-day">' + this.data[i];
              continue;
            }
             
              if ((this.data[i] === 1 && flag) || flag2) {
                flag2 = true;
                className = "prevMonth";
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              }
              
              if (this.data[i] === 1 || flag) {
                className = "curMonth";
                if (this.data[i] === d && m === month) {
                  className += " curDay";
                  document.querySelector(`#${name}`).classList.add('cur_month_name');
                }
                flag = true;
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              } else {
                className = "prevMonth";
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              }
              
              html[i % 7] += '<td class="prevMonth">' + this.data[i];
          }
          
          this.monthName.textContent = this.month;
          this.element.innerHTML = html.join('');
        }
      };
      
      var today = new Date(),
        thisYear = today.getFullYear(),
        thisMonth = today.getMonth(),
        months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
        year_minus = document.querySelector('.year_minus'),
        year_plus = document.querySelector('.year_plus'),
        buttonToday = document.querySelector('#presently'),
        yearListener = document.querySelector('#year_input');
        yearListener.value = thisYear;
 
      function make(year = thisYear) {
        months.forEach((v, i) => {
          calendar.monthName = document.querySelector(`#${v}`);
          calendar.element = document.querySelectorAll('.table_month')[i];
          calendar.update(year, i);
          calendar.render(i, months[i]);
        });
      };
      make();
      buttonToday.classList.add('hide');
    
      year_plus.addEventListener('click', function() {
        yearListener.value = ++thisYear;
        if (yearListener.value == today.getFullYear()) buttonToday.classList.add('hide')
        else buttonToday.classList.remove('hide');
        make(thisYear);
      });
 
      year_minus.addEventListener('click', function() {
        yearListener.value = --thisYear;
        if (yearListener.value == today.getFullYear()) buttonToday.classList.add('hide')
        else buttonToday.classList.remove('hide');
        make(thisYear);
      });
      
      buttonToday.addEventListener('click', function() {
        thisYear = today.getFullYear();
        yearListener.value = thisYear;
        make(thisYear);
        buttonToday.classList.add('hide');
      });
      
      yearListener.addEventListener('change', function() {
        thisYear = yearListener.value;
        if (yearListener.value == today.getFullYear()) buttonToday.classList.add('hide')
        else buttonToday.classList.remove('hide');
        make(+yearListener.value);
      });
      
      const getMidnigth = () => Math.floor(new Date().setHours(24, 0, 0, 0) - new Date().getTime());
      
      let timer = setTimeout(function midUpdate() {
        console.log("r = " + new Date().getTime());
        buttonToday.classList.add('hide');
        thisYear = today.getFullYear();
        yearListener.value = thisYear;
        make(thisYear);
        timer = setTimeout(midUpdate, getMidnigth());
        },getMidnigth());
      
    </script>
  </body>
</html>
Цитата Сообщение от Блондинка йа Посмотреть сообщение
как отследить событие oninput и при смене введённых символов чтобы календарь менял отображение года, а то до сих пор при потере фокуса у поля ввода ничего не происходит...
Потеря фокуса происходит либо по нажатию enter, либо по щелчку на пустом месте.
0
 Аватар для Блондинка йа
13 / 12 / 1
Регистрация: 08.03.2019
Сообщений: 279
05.06.2021, 21:51  [ТС]
Tavashi,

а возможно ли вставить календарь на месяц, и скрывать див с календарём на год при клике на спан, проще говоря чтобы виден был только один блок или на месяц или на год... и чтобы можно было удалить из html-кода блок с каледарём на год/месяц, проще говоря чтобы один скрипт можно было использовать и для маленького календарика на месяц в боковом меню страницы, и на отдельной странице сайта с переключением месяц/год?

PHP/HTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <style>
      @import url('https://fonts.googleapis.com/css?family=Baumans&display=swap');
 
      body {
        width: 860px;
      }
 
      body,
      select,
      input {
        font: 14px serif;
      }
 
      #calendar {
        width: 330px;
        height: 375px;
        display: inline-block;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
 
      #navigation_panel {
        background-color: hsl(210, 100%, 92%);
        min-height: 34px;
        max-height: 78px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
        padding: 10px;
        margin-bottom: 5px;
        text-align: center;
        vertical-align: middle;
        display: -webkit-box;
        display: -webkit-flex;
        display: flex;
        -webkit-box-align: center;
        -webkit-align-items: center;
        align-items: center;
        -webkit-box-pack: center;
        -webkit-justify-content: center;
        justify-content: center;
        -webkit-flex-wrap: wrap;
        flex-wrap: wrap;
      }
 
      #navigation_panel button,
      #navigation_panel #calendar_year {
        background-color: hsl(210, 100%, 85%);
        color: hsl(210, 100%, 45%);
        font: 14px serif;
        border: 1px solid hsl(210, 100%, 45%);
      }
      
      button.year_minus,
      button.year_plus {
      background-color: hsl(210, 100%, 75%);
      color: hsl(210, 100%, 45%);
      font: 24px serif;
      border: 1px solid hsl(210, 100%, 45%);
      width: 55px;
      height: 52px;
      position: relative; top: 2px;
      }
 
      button.year_minus {
      margin-right: -9.5px;
      border-radius: 32px 0 0 32px / 20px 0 0 20px;
      }
      
      button.year_plus {
      margin-left: -9px;
      border-radius: 0 32px 32px 0 / 0 20px 20px 0;
      }
      
      #calendar_month {
        background-color: transparent;
        color: hsl(210, 100%, 45%);
        font: 14px serif;
        border: 1px solid hsl(210, 100%, 45%);
      }
 
      #navigation_panel button {
        height: 34px;
        vertical-align: middle;
      }
 
      #background_month {
        background-color: hsl(210, 100%, 85%);
        display: inline-block;
      }
 
      button.minus {
        width: 28px;
        text-align: center;
        border-radius: 12px 0 0 12px / 10px 0 0 10px;
        margin-right: -1px;
      }
 
      button.plus {
        width: 28px;
        text-align: center;
        border-radius: 0 12px 12px 0 / 0 10px 10px 0;
        margin-left: -1px;
      }
 
      .month_plus {
        margin-right: 35px;
      }
 
      .arrow {
        display: inline-block;
        line-height: 0.5;
      }
 
      #presently {
        background-color: hsl(210, 100%, 90%);
        color: hsl(210, 100%, 45%);
        font: 24px serif;
        border: 1px solid hsl(210, 100%, 45%);
        width: 540px;
        height: 52px;
        
        
 
        margin-top: 10px;
        border-radius: 32px/20px;
      }
 
      #calendar_month {
        width: 89px;
        display: inline-block;
      }
 
      #calendar_year {
        width: 54px;
        display: inline-block;
      }
 
      select {
        height: 34px;
      }
 
      input {
        height: 30px;
        display: inline-block;
        text-align: center;
      }
 
      #table {
        font-family: 'Baumans', cursive;
        table-layout: fixed;
        width: 100%;
        height: 413px;
        padding: 2px;
      }
 
      #table,
      td {
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 6px/4px;
      }
 
      td {
        margin: 1px;
        text-align: center;
      }
 
      #table tbody td.prevMonth {
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      } /* будние дни предыдущего месяца */
      
      #table tbody tr:nth-child(n + 6) td.prevMonth {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      } /* выходные дни предыдущего месяца */
      
      #table tbody td.nextMonth {
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      } /* будние дни следующего месяца */
      
      #table tbody tr:nth-child(n + 6) td.nextMonth {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 80%);
        border: 1px solid hsl(0, 0%, 80%);
      } /* выходные дни следующего месяца */
      
      #presently.hide {
        display: none;
      }
 
      #table tbody tr td.week-day {
        background-color: hsl(210, 100%, 85%);
        color: hsl(210, 100%, 50%);
        border: 1px solid hsl(0, 0%, 60%);
        width: 20%;
      } /* день недели */
      
      #table tbody tr:nth-child(n + 6) td.week-day {
        background-color: hsl(348, 100%, 85%);
        color: hsl(348, 100%, 50%);
        border: 1px solid hsl(0, 0%, 60%);
      } /* день недели выходной*/
      
      #table tbody tr td.week-day.curDay {
        border: 1px solid hsl(210, 100%, 50%);
        background-color: hsl(210, 100%, 70%); /**/
        color: hsl(210, 100%, 98%);
        font-weight: bold;
        text-shadow:
          1px 1px hsl(210, 100%, 50%),
          -1px 1px hsl(210, 100%, 50%),
          1px -1px hsl(210, 100%, 50%),
          -1px -1px hsl(210, 100%, 50%),
          1px 0 hsl(210, 100%, 50%),
          0 1px hsl(210, 100%, 50%),
          -1px 0 hsl(210, 100%, 50%),
          0 -1px hsl(210, 100%, 50%);
        letter-spacing: 2px;
      } /* сегодн день недели */
      
      #table tbody tr:nth-child(n + 6) td.week-day.curDay {
        border: 1px solid hsl(348, 100%, 50%);
        background-color: hsl(348, 100%, 75%); /**/
        color: hsl(348, 100%, 98%);
        font-weight: bold;
        text-shadow: 1px 1px hsl(348, 100%, 50%), 1px -1px hsl(348, 100%, 50%), -1px 1px hsl(348, 100%, 50%), -1px -1px hsl(348, 100%, 50%), 1px 0 hsl(348, 100%, 50%), -1px 0 hsl(348, 100%, 50%), 0 1px hsl(348, 100%, 50%), 0 -1px hsl(348, 100%, 50%);
        letter-spacing: 2px;
      } /* сегодн день недели выходной */
      
      #table tbody td {
        background-color: hsl(210, 100%, 90%);
        color: hsl(210, 100%, 50%);
      } /* будние дни текущего месяца */
      
      #table tbody tr:nth-child(n + 6) td {
        background-color: hsl(348, 100%, 90%);
        color: hsl(348, 100%, 50%);
      } /* выходные дни текущего месяца */
      
      #table tr td.curMonth.curDay {
        background-color: hsl(210, 100%, 75%); /**/
        border: 1px solid hsl(210, 100%, 50%);
        font-weight: bold;
        color: hsl(210, 100%, 100%);
        text-shadow: 1px 1px hsl(210, 100%, 50%), -1px 1px hsl(210, 100%, 50%), 1px -1px hsl(210, 100%, 50%), -1px -1px hsl(210, 100%, 50%), 1px 0 hsl(210, 100%, 50%), 0 1px hsl(210, 100%, 50%), -1px 0 hsl(210, 100%, 50%), 0 -1px hsl(210, 100%, 50%);
        letter-spacing: 3px;
      } /* сегодня будний */
      
      #table tr:nth-child(n + 6) td.curMonth.curDay {
        background-color: hsl(348, 100%, 75%); /**/
        border: 1px solid hsl(348, 100%, 50%);
        color: hsl(348, 100%, 100%);
        text-shadow: 1px 1px hsl(348, 100%, 50%), 1px -1px hsl(348, 100%, 50%), -1px 1px hsl(348, 100%, 50%), -1px -1px hsl(348, 100%, 50%), 1px 0 hsl(348, 100%, 50%), -1px 0 hsl(348, 100%, 50%), 0 1px hsl(348, 100%, 50%), 0 -1px hsl(348, 100%, 50%);
        letter-spacing: 3px;
      } /* сегодня выходной */
 
      #calendar {
        display: flex;
        flex-direction: column;
      }
 
      .content_month {
        flex: 1;
      }
 
      #table {
        height: 100%;
      }
 
      button,
      select,
      input {
        outline: none;
      }
      
      #calendar_month {
      margin-bottom: 50px;
      }
      
      #calendar_month,
      .td_month {
        width: 250px;
        height: 290px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
      }
 
      #January,
      #February,
      #March,
      #April,
      #May,
      #June,
      #July,
      #August,
      #September,
      #October,
      #November,
      #December {
        background-color: hsl(210, 100%, 86%);
        color: hsl(210, 100%, 50%);
        font: bold 18px serif;
        text-align: center;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
        padding: 5px;
        margin: 0 0 5px 0;
      }
      
      #num_year {
        font: bold 24px serif;
        width: auto;
        padding: 5px;
        background-color: hsl(210, 100%, 86%);
        color: hsl(210, 100%, 50%);
        border: 1px solid hsl(0, 0%, 66%);
        text-align: center;
        padding: 10px;
        margin: 0 0 5px 0;
        border-radius: 8px;
        white-space: nowrap;
      }
 
      .day {
        border: 1px solid hsl(0, 0%, 66%);
        width: auto;
        line-height: 30px;
        text-align: center;
        margin: 1px;
        background-color: hsl(210, 100%, 95%);
        color: hsl(210, 100%, 50%);
      }
 
      .table_month_v {
        table-layout: fixed;
        width: 100%;
        height: 320px;
        border: 1px solid hsl(0, 0%, 66%);
        border-radius: 4px;
      }
 
      .table_month_v tr td:nth-child(1) {
        width: 20%;
        font-weight: bold;
      }
 
      .table_month_v tr td.day:nth-child(1) {
        background-color: hsl(210, 100%, 86%);
        color: hsl(210, 100%, 50%);
      } /* названия дней недели будни */
 
      .table_month_v tr:nth-child(n + 6) td.day:nth-child(1) {
        background-color: hsl(348, 100%, 86%);
        color: hsl(348, 100%, 50%);
      } /* названия дней недели выходные */
 
      .table_month_v tr:nth-child(n + 6) td.day {
        background-color: hsl(348, 100%, 95%);
        color: hsl(348, 100%, 50%);
      }
 
      #year_input {
        background-color: hsl(210, 100%, 90%);
        color: hsl(210, 100%, 50%);
        border: 1px solid hsl(210, 100%, 50%);
        display: inline-block;
        text-align: center;
        font: bold 24px serif;
        width: 100px;
        padding: 10px;
      }
      
      #January.cur_month_name,
      #February.cur_month_name,
      #March.cur_month_name,
      #April.cur_month_name,
      #May.cur_month_name,
      #June.cur_month_name,
      #July.cur_month_name,
      #August.cur_month_name,
      #September.cur_month_name,
      #October.cur_month_name,
      #November.cur_month_name,
      #December.cur_month_name {
        background-color: hsl(210, 100%, 70%);
        color: hsl(210, 100%, 98%);
        font: bold 18px serif;
        text-align: center;
        border: 1px solid hsl(210, 100%, 50%);
        border-radius: 4px;
        padding: 5px;
        margin: 0 0 5px 0;
        text-shadow:
        1px 1px hsl(210, 100%, 50%),
        -1px 1px hsl(210, 100%, 50%),
        1px -1px hsl(210, 100%, 50%),
        -1px -1px hsl(210, 100%, 50%),
        1px 0 hsl(210, 100%, 50%),
        0 1px hsl(210, 100%, 50%),
        -1px 0 hsl(210, 100%, 50%),
        0 -1px hsl(210, 100%, 50%);
        letter-spacing: 2px;
      } /* название текущего месяца */
 
    </style>
  </head>
 
  <body>
    <div id="calendar">
    <div id="calendar_month">
      <div id="navigation_panel">
      <button class="month_minus minus"><span class="arrow"></span></button>
      <span id="background_month"><select id="calendar_month"></select></span>
      <button class="month_plus plus"><span class="arrow"></span></button>
      <button class="year_minus minus"><span class="arrow"></span></button>
      <input type="number" size="4" id="calendar_year"/>
      <button class="year_plus plus"><span class="arrow"></span></button><br/>
      <button id="presently">сегодня</button>
      </div>
      <table class="table_month_v"></table>
      <span id="select_year">календарь на год</span>
    </div>
    </div>
    <div id="calendar_year">
    <div id="num_year">
      Календарь на
      <button class="year_minus"></button>
      <input id="year_input" type="number" size="4" value="" />
      <button class="year_plus"></button>
      год.<br />
      <button id="presently">сегодня</button>
    </div>
    <table id="table">
      <tr>
        <td class="td_month">
            <div id="January"></div>
            <table class="table_month_v"></table>
        </td>
        <td class="td_month">
            <div id="February"></div>
            <table class="table_month_v"></table>
        </td>
        <td class="td_month">
            <div id="March"></div>
            <table class="table_month_v"></table>
        </td>
      </tr>
      <tr>
        <td class="td_month">
            <div id="April"></div>
            <table class="table_month_v"></table>
        </td>
        <td class="td_month">
            <div id="May"></div>
            <table class="table_month_v"></table>
        </td>
        <td class="td_month">
            <div id="June"></div>
            <table class="table_month_v"></table>
        </td>
      </tr>
      <tr>
        <td class="td_month">
            <div id="July"></div>
            <table class="table_month_v"></table>
        </td>
        <td class="td_month">
            <div id="August"></div>
            <table class="table_month_v"></table>
        </td>
        <td class="td_month">
            <div id="September"></div>
            <table class="table_month_v"></table>
        </td>
      </tr>
      <tr>
        <td class="td_month">
            <div id="October"></div>
            <table class="table_month_v"></table>
        </td>
        <td class="td_month">
            <div id="November"></div>
            <table class="table_month_v"></table>
        </td>
        <td class="td_month">
            <div id="December"></div>
            <table class="table_month_v"></table>
        </td>
      </tr>
    </table>
    <span id="select_month">календарь на месяц</span>
  </div>
  </div>
    <script>
      var calendar = {
        update: function(year, month) {
          this.year = year;
          this.month = ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'][month];
          var startDay = new Date(year, month, 1);
          var offsetDay = (startDay.getDay() || 7) - 1;
          startDay.setDate(startDay.getDate() - offsetDay);
          var lastDay = new Date(startDay);
          var days = new Date(year, month + 1, 0).getDate();
          days = Math.ceil((days + offsetDay) / 7) * 7;
          lastDay.setDate(lastDay.getDate() + days);
          this.data = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
          while (startDay < lastDay) {
            this.data.push(startDay.getDate());
            startDay.setHours(24);
          }
        },
        
        getCurDay: function(month, m, d, flag = false, flag2 = false) {
            var curDay;
            for (var i = 0; i < this.data.length; i++) {
            if (m === month) {
              if ((this.data[i] === 1 && flag) || flag2) {
                flag2 = true;
                continue;
              }
              if (this.data[i] === 1 || flag) {
                if (this.data[i] === d) curDay = i % 7;
                flag = true;
                continue;
              }
            }
          }
          return curDay;
        }, 
        
        render: function(month, name) {
          var html = ['<tr>', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>', '<tr>'];
          var m = new Date().getMonth(),
            d = new Date().getDate(),
            flag = false,
            flag2 = false,
            curDay = this.getCurDay(month, m, d),
            className;
          
          for (var i = 0; i < this.data.length; i++) {
            if (i >= 0 && i <= 6) {
                if (i === curDay) html[i % 7] += '<td class="week-day curDay">' + this.data[i];
              else html[i % 7] += '<td class="week-day">' + this.data[i];
              continue;
            }
             
              if ((this.data[i] === 1 && flag) || flag2) {
                flag2 = true;
                className = "prevMonth";
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              }
              
              if (this.data[i] === 1 || flag) {
                className = "curMonth";
                if (this.data[i] === d && m === month) {
                  className += " curDay";
                  document.querySelector(`#${name}`).classList.add('cur_month_name');
                }
                flag = true;
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              } else {
                className = "prevMonth";
                html[i % 7] += '<td class="' + className + '">' + this.data[i];
                continue;
              }
              
              html[i % 7] += '<td class="prevMonth">' + this.data[i];
          }
          
          this.monthName.textContent = this.month;
          this.element.innerHTML = html.join('');
        }
      };
      
      var today = new Date(),
        thisYear = today.getFullYear(),
        thisMonth = today.getMonth(),
        months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
        year_minus = document.querySelector('.year_minus'),
        year_plus = document.querySelector('.year_plus'),
        buttonToday = document.querySelector('#presently'),
        yearListener = document.querySelector('#year_input');
        yearListener.value = thisYear;
 
      function make(year = thisYear) {
        months.forEach((v, i) => {
          calendar.monthName = document.querySelector(`#${v}`);
          calendar.element = document.querySelectorAll('.table_month_v')[i];
          calendar.update(year, i);
          calendar.render(i, months[i]);
        });
      };
      make();
      buttonToday.classList.add('hide');
    
      year_plus.addEventListener('click', function() {
        yearListener.value = ++thisYear;
        if (yearListener.value == today.getFullYear()) buttonToday.classList.add('hide')
        else buttonToday.classList.remove('hide');
        make(thisYear);
      });
 
      year_minus.addEventListener('click', function() {
        yearListener.value = --thisYear;
        if (yearListener.value == today.getFullYear()) buttonToday.classList.add('hide')
        else buttonToday.classList.remove('hide');
        make(thisYear);
      });
      
      buttonToday.addEventListener('click', function() {
        thisYear = today.getFullYear();
        yearListener.value = thisYear;
        make(thisYear);
        buttonToday.classList.add('hide');
      });
      
      yearListener.addEventListener('input', function() {
        thisYear = yearListener.value;
        if (yearListener.value == today.getFullYear()) buttonToday.classList.add('hide')
        else buttonToday.classList.remove('hide');
        make(+yearListener.value);
      });
      
      const getMidnigth = () => Math.floor(new Date().setHours(24, 0, 0, 0) - new Date().getTime());
      
      let timer = setTimeout(function midUpdate() {
        console.log("r = " + new Date().getTime());
        buttonToday.classList.add('hide');
        thisYear = today.getFullYear();
        yearListener.value = thisYear;
        make(thisYear);
        timer = setTimeout(midUpdate, getMidnigth());
        },getMidnigth());
      
    </script>
  </body>
</html>
0
Надоела реклама? Зарегистрируйтесь и она исчезнет полностью.
raxper
Эксперт
30234 / 6612 / 1498
Регистрация: 28.12.2010
Сообщений: 21,154
Блог
05.06.2021, 21:51
Помогаю со студенческими работами здесь

Как сделать что бы значения из God выводилось не в отдельную ячейку а рядом с названия столбца год пример год 2018
CTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset=&quot;UTF-8&quot;&gt; &lt;title&gt;Таблица(Шаблон представления информации о...

Как получить значение позиции курсора(фокуса) в DateTimePicker (день,месяц или год), когда календарь закрыт?
Доброго времени суток. Подскажите, как получить значение позиции курсора(фокуса) в DateTimePicker (день,месяц или год), когда календарь...

Календарь На Год
Привет! В стандартном лотусовом календаре есть соритровки на день, неделю и месяц. Нет на год. Поставлена задача показать календарь...

Календарь на год
Здравствуйте! Хочу сделать календарь событий на год типа как тут http://www.mbo4x4.ru/index.phtml?way=rasp но покрасивее нашел...

Календарь на год
Доброго времени суток, никак не получается решить задачу. Написать программу формирования календаря для любого года, начиная с 1900 (1...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
38
Ответ Создать тему
Новые блоги и статьи
SDL3 для Web (WebAssembly): Обработчик клика мыши в браузере ПК и касания экрана в браузере на мобильном устройстве
8Observer8 02.02.2026
Содержание блога Для начала пошагово создадим рабочий пример для подготовки к экспериментам в браузере ПК и в браузере мобильного устройства. Потом напишем обработчик клика мыши и обработчик. . .
Философия технологии
iceja 01.02.2026
На мой взгляд у человека в технических проектах остается роль генерального директора. Все остальное нейронки делают уже лучше человека. Они не могут нести предпринимательские риски, не могут. . .
SDL3 для Web (WebAssembly): Вывод текста со шрифтом TTF с помощью SDL3_ttf
8Observer8 01.02.2026
Содержание блога В этой пошаговой инструкции создадим с нуля веб-приложение, которое выводит текст в окне браузера. Запустим на Android на локальном сервере. Загрузим Release на бесплатный. . .
SDL3 для Web (WebAssembly): Сборка C/C++ проекта из консоли
8Observer8 30.01.2026
Содержание блога Если вы откроете примеры для начинающих на официальном репозитории SDL3 в папке: examples, то вы увидите, что все примеры используют следующие четыре обязательные функции, а. . .
SDL3 для Web (WebAssembly): Установка Emscripten SDK (emsdk) и CMake для сборки C и C++ приложений в Wasm
8Observer8 30.01.2026
Содержание блога Для того чтобы скачать Emscripten SDK (emsdk) необходимо сначало скачать и уставить Git: Install for Windows. Следуйте стандартной процедуре установки Git через установщик. . . .
SDL3 для Android: Подключение Box2D v3, физика и отрисовка коллайдеров
8Observer8 29.01.2026
Содержание блога Box2D - это библиотека для 2D физики для анимаций и игр. С её помощью можно определять были ли коллизии между конкретными объектами. Версия v3 была полностью переписана на Си, в. . .
Инструменты COM: Сохранение данный из VARIANT в файл и загрузка из файла в VARIANT
bedvit 28.01.2026
Сохранение базовых типов COM и массивов (одномерных или двухмерных) любой вложенности (деревья) в файл, с возможностью выбора алгоритмов сжатия и шифрования. Часть библиотеки BedvitCOM Использованы. . .
SDL3 для Android: Загрузка PNG с альфа-каналом с помощью SDL_LoadPNG (без SDL3_image)
8Observer8 28.01.2026
Содержание блога SDL3 имеет собственные средства для загрузки и отображения PNG-файлов с альфа-каналом и базовой работы с ними. В этой инструкции используется функция SDL_LoadPNG(), которая. . .
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2026, CyberForum.ru