Показать сообщение отдельно
  #1 (permalink)  
Старый 30.05.2021, 16:03
Аватар для Блондинка
Профессор
Отправить личное сообщение для Блондинка Посмотреть профиль Найти все сообщения от Блондинка
 
Регистрация: 24.02.2019
Сообщений: 806

возможно ли чтобы скрипт создавал другой html-код?
Сообщение от рони Посмотреть сообщение
Блондинка,
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Calendar</title>
  </head>
  <body>
    <style>
      .month,
      .month.vert .week,
      .day {
        display: inline-block;
      }
      .month.vert .day {
        display: block;
      }
      .day {
        border: 1px solid #ccc;
        width: 30px;
        line-height: 30px;
        text-align: center;
        margin: 1px;
      }
    </style>
    <div class="month"></div>
    <script>
      var calendar = {
        update: function(year, month) {
          this.days.length = 7;
          var stepDay = new Date(year, month, 1);
          stepDay.setDate(stepDay.getDate() + 0 - ((stepDay.getDay() + 6) % 7));
          var lastDay = new Date(year, month + 1, 0);
          lastDay.setDate(lastDay.getDate() + 6 - ((lastDay.getDay() + 6) % 7));
          while (stepDay <= lastDay) {
            this.days.push(stepDay.getDate());
            stepDay.setHours(24);
          }
        },
        render: function() {
          var html = '';
          for (var i = 0, j = 0; i < this.days.length; j = ++i % 7) {
            if (j == 0) html += '<div class="week">';
            html += '<div class="day">' + this.days[i] + '</div>';
            if (j == 6) html += '</div>';
          }
          this.element.innerHTML = html;
        },
        toggle: function() {
          this.element.classList.toggle('vert');
        },
      };
      var today = new Date(),
        thisYear = today.getFullYear(),
        thisMonth = today.getMonth();
      calendar.days = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];

      calendar.element = document.querySelector('.month');
      calendar.element.addEventListener('click', function() {
        calendar.toggle();
      });
      calendar.update(thisYear, thisMonth);
      calendar.render();
    </script>
  </body>
</html>
возможно ли чтобы скрипт создавал такие вот таблицы, с id vertical и gorizontal
May 2021 <br>
<table class="vertical" cellspacing="2" cellpadding="5" border="1" align="center">
<tr> <td> Пн </td> <td> 26 </td> <td> 3 </td> <td> 10 </td> <td> 17 </td> <td> 24 </td> <td> 31 </td> </tr>
<tr> <td> Вт </td> <td> 27 </td> <td> 4 </td> <td> 11 </td> <td> 18 </td> <td> 25 </td> <td> 1 </td> </tr>
<tr> <td> Ср </td> <td> 28 </td> <td> 5 </td> <td> 12 </td> <td> 19 </td> <td> 26 </td> <td> 2 </td> </tr>
<tr> <td> Чт </td> <td> 29 </td> <td> 6 </td> <td> 13 </td> <td> 20 </td> <td> 27 </td> <td> 3 </td> </tr>
<tr> <td> Пт </td> <td> 30 </td> <td> 7 </td> <td> 14 </td> <td> 21 </td> <td> 28 </td> <td> 4 </td> </tr>
<tr> <td> Сб </td> <td> 1 </td> <td> 8 </td> <td> 15 </td> <td> 22 </td> <td> 29 </td> <td> 5 </td> </tr>
<tr> <td> Вс </td> <td> 2 </td> <td> 9 </td> <td> 16 </td> <td> 23 </td> <td> 30 </td> <td> 6 </td> </tr>
</table>
<br>
<table class="gorizontal" cellspacing="2" cellpadding="5" border="1" align="center">
<tr> <td> Пн </td> <td> Вт </td> <td> Ср </td> <td> Чт </td> <td> Пт </td> <td> Сб </td> <td> Вс </td> </tr>
<tr> <td> 26 </td> <td> 27 </td> <td> 28 </td> <td> 28 </td> <td> 30 </td> <td> 1 </td> <td> 2 </td> </tr>
<tr> <td> 3 </td> <td> 4 </td> <td> 5 </td> <td> 6 </td> <td> 7 </td> <td> 8 </td> <td> 9 </td> </tr>
<tr> <td> 10 </td> <td> 11 </td> <td> 12 </td> <td> 13 </td> <td> 14 </td> <td> 15 </td> <td> 16 </td> </tr>
<tr> <td> 17 </td> <td> 18 </td> <td> 19 </td> <td> 20 </td> <td> 21 </td> <td> 22 </td> <td> 23 </td> </tr>
<tr> <td> 24 </td> <td> 25 </td> <td> 26 </td> <td> 27 </td> <td> 28 </td> <td> 29 </td> <td> 30 </td> </tr>
<tr> <td> 31 </td> <td> 1 </td> <td> 2 </td> <td> 3 </td> <td> 4 </td> <td> 5 </td> <td> 6 </td> </tr>
</table>


вот сам скрипт

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>calendar-rotate</title>
    <style type="text/css">
      #calendar_rotate {
        border: 1px solid hsl(0,0%,66%);
        padding: 5px;
        display: inline-block;
        width: 373px;
      }
      #navigation_panel { 
        border: 1px solid hsl(0,0%,66%);
        padding: 5px 10px;
        margin: 0 0 5px 0;
        display: inline-block;
        white-space: nowrap;
      }
      #background_month {
      background-color: hsl(210,100%,85%);
      display: inline-block; }
      #month_select {
      background-color: transparent;
      color: hsl(210,100%,45%);
      font: 14px serif;
      border: 1px solid hsl(210,100%,45%); }
      .month {
        border: 1px solid hsl(0,0%,66%);
        display: flex;
        flex-flow: column wrap;
        justify-content: space-between;
        width: 100%;
        height: 367px;
        padding: 1px;
      }
      .vert {
        border: 1px solid #ff0;
        height auto;
        display: flex;
        justify-content: space-between;
      }
      .vert .week {
        width: auto;
        border: 1px solid #090;
        flex: 1 1 auto;
        align-self: stretch;
      }
      .mont
      .vert .week .day {
        height 11.52%;
      }
      .month .week {
        border: 1px solid #00a;
        flex: 1 1 auto;
        align-self: stretch;
        width: 100%;
        height: auto;
      }
      .month .week .day {
        width 1.947em;;
        height 1.85em;
      }
      .month,
      .month.vert .week,
      .day {
        display: inline-block;
        width: auto;
      }
      .month.vert .day {
        display: block;
        width: 1.85em;
      }
      .day {
        border: 1px solid hsl(0,0%,66%);
        width: 1.964em;
        line-height: 30px;
        text-align: center;
        padding: 3.5px;
        margin: 1px;
        background-color: hsl(210,100%,90%);
        color: hsl(210,100%,50%);
      }
      .day:nth-child(7n + 6), .day:nth-child(7n + 7) {
        background-color: hsl(348,100%,90%);
        color: hsl(348,100%,50%);
      }
      select {
        width: 109px;
        height: 29.5px;
      }
      input { 
        border: 1px solid hsl(0,0%,66%);
        width: 54px;
        height: 25.5px;display: inline-block;
        text-align: center;
      }
      #month_minus, #year_minus { 
      width: 28px;
      text-align: center;
      border-radius: 12px 0 0 12px / 10px 0 0 10px;
      margin: 0 -6px 0 0;
      position: relative; top: 1.5px; }
      #month_plus, #year_plus {
      width: 28px;
      text-align: center;
      border-radius: 0 12px 12px 0 / 0 10px 10px 0;
      margin: 0 0 0 -6px;
      position: relative; top: 1.5px; }
      #month_minus, #month_plus, #year_minus, #year_plus, #year_input {
      background-color: hsl(210,100%,85%);
      color: hsl(210,100%,45%);
      font: 14px serif;
      border: 1px solid hsl(210,100%,45%);}
    </style>
    </head>
    <body>
        <div id="calendar_rotate">
        <div id="navigation_panel">
        <button id="month_minus">◀</button>
        <span id="background_month"><select id="month_select"></select></span>
        <button id="month_plus">▶</button>
        <button id="year_minus">◀</button>
        <input id="year_input" type="number" size="4" value=""/> 
        <button id="year_plus">▶</button>
        <button id="month_rotate">➙</button>
        </div>
        <div class="month vert"></div>
        <script>
          var calendar = {
            update: function(year, month) {
              this.days.length = 7;
              var stepDay = new Date(year, month, 1);
              stepDay.setDate(stepDay.getDate() + 0 - ((stepDay.getDay() + 6) % 7));
              var lastDay = new Date(year, month + 1, 0);
              lastDay.setDate(lastDay.getDate() + 6 - ((lastDay.getDay() + 6) % 7));
              while (stepDay <= lastDay) {
                this.days.push(stepDay.getDate());
                stepDay.setHours(24);
              }
            },
            render: function() {
              var html = '';
              for (var i = 0, j = 0; i < this.days.length; j = ++i % 7) {
                if (j == 0) html += '<div class="week">';
                html += '<div class="day">' + this.days[i] + '</div>';
                if (j == 6) html += '</div>';
              }
              this.element.innerHTML = html;
            },
            toggle: function() {
              this.element.classList.toggle('vert');
            },
          };
          var today = new Date(),
            thisYear = today.getFullYear(),
            thisMonth = today.getMonth();
          calendar.days = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'];
          selector = document.getElementById('month_select');
          month_list = ['Январь', 'Февраль', 'Март', 'Апрель', ' Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь'];
          for (let i = 0; i < month_list.length; i++){
            selector.options[i] = new Option(month_list[i], i);
          }
          selector.selectedIndex = thisMonth;
          selector.addEventListener('change', load);
          document.getElementById('year_input').addEventListener('change', load);
          calendar.element = document.querySelector('.month');
          document.getElementById('month_rotate').addEventListener('click', function() {
            calendar.toggle();
          });
          function load(){
              let year = document.getElementById('year_input').value;
              let month = selector.selectedIndex;
              calendar.update(year, month);
              calendar.render();
          }
          document.addEventListener("DOMContentLoaded", ()=>{
            document.getElementById('year_input').value = thisYear;
            load();
          });
          
          
        </script>
      </div>
    </body>
</html>
Ответить с цитированием