我正在使用日期选择器来选择出生日期。我有三个输入框。输入31/08/1991
生日后自动计算年份月份和日期21 year
1 months
2 Days
。
$(function() {
$("#dob").datepicker({
changeMonth : true,
changeYear : true,
defaultDate: '-30yr',
yearRange: 'c-25:c+35',
onSelect: function(selectedDate) {
var a = $("#dob").datepicker( "getDate" );
var today = new Date();
var age = Math.floor((today-a) / ( 24 * 60 * 60 * 1000 ));
var year = Math.round(age/365);
var month = Math.round(age/30);
$('#ages').val(year);
}
});
$("#dob").datepicker("option", "dateFormat", 'dd-mm-yy');
$("input:submit, a, button", ".registerSubmit").button();
});