How do you make a match check for the original date and date?



  • In general the situation is that there are three blocks on the page, each with the php + mysql added its date:

    <div class="block">
        <div class="post-date" data-day="24.08.2016">
            <span>24</span>
            <span>Авг</span>
        </div>
        <div>Сегодня</div>
        <div>Завтра</div>
    </div
    <div class="block">
        <div class="post-date" data-day="18.08.2016">
            <span>18</span>
            <span>Авг</span>
        </div>
        <div>Сегодня</div>
        <div>Завтра</div>
    </div
    <div class="block">
        <div class="post-date" data-day="02.08.2016">
            <span>02</span>
            <span>Авг</span>
        </div>
        <div>Сегодня</div>
        <div>Завтра</div>
    </div
    

    I can't make it that if the date indicated in the block matches the current date, the block with the word "Today" takes the dispaly meaning: block, and the block with the post-date class was dispaly: none. A similar situation, and with the Tomorrow block, if there's one day left before the date of the said, the Tomorrow block is displayed. And if there are more than two days before the current date, nothing happens. ♪ ♪

    I've make a sketch, but it's not working, please help me! With respect! Oleg.

    var d = 1;
    var now = new Date();
    var day = now.getDate();// текущий день
    var month = now.getMonth(); // текущий месяц
    var tomorrowDate = day+d; // день для отражения блока - "завтра"
    var datomorrowDate = day+d+d; // дни при которых ничего не надо отображать
    

    var x = document.querySelectorAll(".post-date");
    var d = 1;
    for (var i = 0; i < x.length; i++) {
    var eventDate = x[i].data('day'); // не могу вытащить значение даты блока:(((
    }



  • var now = new Date();
    var today = ('0' + now.getDate()).slice(-2) + '.' + ('0' + (now.getMonth()+1)).slice(-2) + '.' + now.getFullYear();
    var nextDate = new Date(now.setDate(now.getDate() + 1));
    var tomorrow = ('0' + nextDate.getDate()).slice(-2) + '.' + ('0' + (nextDate.getMonth()+1)).slice(-2) + '.' + nextDate.getFullYear();
    

    var events = document.querySelectorAll(".post-date");
    for(var i = 0; i < events.length; i++) {
    var eventDate = events[i].getAttribute('data-day');
    if(eventDate == today) {
    events[i].parentNode.querySelector('.today').style.display = 'block';
    }
    if(eventDate == tomorrow) {
    events[i].parentNode.querySelector('.tomorrow').style.display = 'block';
    }
    }

    .block {
    border: 1px solid black;
    margin: 5px;
    }

    .post-date {
    display: block;
    }

    .today, .tomorrow {
    display: none;
    }

    <div class="block">
    <div class="post-date" data-day="19.07.2016">
    <span>19</span>
    <span>Июля</span>
    </div>
    <div class="today">Сегодня</div>
    <div class="tomorrow">Завтра</div>
    </div>
    <div class="block">
    <div class="post-date" data-day="18.07.2016">
    <span>18</span>
    <span>Июля</span>
    </div>
    <div class="today">Сегодня</div>
    <div class="tomorrow">Завтра</div>
    </div>
    <div class="block">
    <div class="post-date" data-day="02.08.2016">
    <span>02</span>
    <span>Августа</span>
    </div>
    <div class="today">Сегодня</div>
    <div class="tomorrow">Завтра</div>
    </div>




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2