本例中用的是easyUI的datebox
$('#cal_birthday').datebox({
onSelect: function(date){
//根据选则的日期计算年龄
//alert(date.getFullYear()+":"+(date.getMonth()+1)+":"+date.getDate()); // 2017:6:12
var years = 0;
var diff = 0;
d = new Date();
if(date.getFullYear() < d.getFullYear()){
years = d.getFullYear() - date.getFullYear();
if(date.getMonth() > d.getMonth()){
diff = -1;
}else if(date.getMonth() == d.getMonth()){
if(date.getDate() > d.getDate()){diff = -1;}
}
}
$("#cal_age").html(years+diff);
}
});