本例中用的是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);
    }
    });

 

相关文章:

  • 2021-11-30
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2021-11-30
  • 2022-12-23
  • 2021-09-30
相关资源
相似解决方案