//获取当前时间的年月日 var myDate = new Date(); var now_year = myDate.getFullYear(); var now_month = myDate.getMonth()+1; var now_day = myDate.getDate();
var birthday=$('#birthday').val()//获取出生日期 var birth_year=birthday.split('-')[0] var birth_month=birthday.split('-')[1] var birth_day=birthday.split('-')[2] //通过对比年、月、日判断当前年龄 if(now_year>birth_year&&now_month<birth_month||now_year>birth_year&&now_month==birth_month&&now_day<birth_day){ var newage=BigNumber(now_year).minus(birth_year) }else if(now_year>birth_year&&now_month>birth_month) { var newage=BigNumber(now_year).minus(birth_year).plus(1) }else if(now_year>birth_year&&now_month==birth_month&&now_day==birth_day||now_year>birth_year&&now_month==birth_month&&now_day>birth_day) { var newage=BigNumber(now_year).minus(birth_year).plus(1) }else { var newage=0 }
$('#age').val(newage)//当年年龄