Domanda

I'm creating a site that has has many events and days/holidays, they have a function that happens when countdown to that date completes, all similar to this ..

$(document).ready(function() {
$("#TheEvents").countdown({
date: "july 04, 2014 12:00",
"onComplete" : function(event) { 
$(".ThisEvent").slideUp("slow");  
}           
});
});

Since they all have a set date every year my question is - is there a way to put the current year were '2014' is like {TheCurrentYear} ?

I really dont want to have to go and change to 2015 etc. to restart countdown after every event completes :-)

Thanks for your help.

È stato utile?

Soluzione

Just calculate the year dynamically by creating a new Date object, and then calling getFullYear():

$("#TheEvents").countdown({
    date: "july 04, " + new Date().getFullYear() + " 12:00",
    onComplete : function(event) { 
        $(".ThisEvent").slideUp("slow");  
    }           
});
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top