$('#idNumber').blur(function (){
var UUserCard = $("#idNumber").val();
if(UUserCard!=null&&UUserCard.trim()!=""){
var birthday = UUserCard.substring(6, 10) + "-" + UUserCard.substring(10, 12) + "-" + UUserCard.substring(12, 14);
$("#birthday").val(birthday);
$('.date-picker').datepicker('setStartDate',birthday);
if (parseInt(UUserCard.substr(16, 1)) % 2 == 1) {
$("#gender1").val(1);//男
$("#gender").val(1);
} else {
$("#gender1").val(2);//女
$("#gender").val(2);
}
//获取年龄
var myDate = new Date();
var month = myDate.getMonth() + 1;
var day = myDate.getDate();
var age = myDate.getFullYear() - UUserCard.substring(6, 10);
// if (UUserCard.substring(10, 12) < month || UUserCard.substring(10, 12) == month && UUserCard.substring(12, 14) <= day) {
// age++;
// }
$("#age").val(age);
}
});
通过身份证号动态获取生日、性别、年龄
最新推荐文章于 2023-09-27 19:48:07 发布