到目前为止,我能想到的唯一数学方法是:
var age = 18
var today = new Date();
var myDate = new Date();
myDate.setFullYear(2013,3,13); /* My birthday is april 13th */
var y = (today - myDate);
var days = ( y / (1000*60*60*24));
if(days >= 360){
var age = age +1;
}
if(days >= 720){
var age = age +1;
}
//etc......
document.write(age);
有没有更好的方法来做if语句?这样我就不用每年都写一篇了?我想不通!