mardi 22 mars 2016

Can't figure out how to have text content shown based on the date automatically

I am looking to have text shown in a paragraph that changes based on the date. This is for a hotel website where the price is based on the seasons and I find it horribly tacky to list out every season's rate in the main price section. Here is my current code that I am having trouble fiddling with to get it to do what I want:

$(function() {
  $(".DateDiv").each(function(index) {
    var sRange = $(this).find(".DateRange").html();
    var arrTemp = sRange.split(" to ");
    var dtFrom = new Date(arrTemp[0]);
    var dtTo = new Date(arrTemp[1]);
    var dtNow = new Date();
    if (dtNow >= dtFrom && dtNow <= dtTo)
      $(this).show();
  });
});
.DateRange,
.DateDiv {
  display: none;
}
<script src="http://ift.tt/1qRgvOJ"></script>
<div class="DateDiv"><span class="DateRange">3/1/2016 to 5/14/2016</span>$89</div>
<div class="DateDiv"><span class="DateRange">5/15/2016 to 9/14/2016</span>$129</div>
<div class="DateDiv"><span class="DateRange">9/15/2016 to 12/1/2016</span>$89</div>
<div class="DateDiv"><span class="DateRange">12/1/2016 to 2/28/2017</span>$49</div>

This works on a basic end of what I want, in that it shows the price of what I need during that rate period though I will have to manually change the code on a yearly basis... if someone knows how to set it up so I don't have to do that, that would be great.



Can't figure out how to have text content shown based on the date automatically

Aucun commentaire:

Enregistrer un commentaire