(13条消息) js前端通过身份证号判断年龄、性别、出生日期。_js判断性别_renlmmm的博客-CSDN博客
//通过身份证号计算年龄、性别、出生日期 function idCard(userCard, num) { //获取出生日期 if (num == 1) { birth = userCard.substring(6, 10) + "-" + userCard.substring(10, 12) + "-" + userCard.substring(12, 14); return birth; } //获取性别 if (num == 2) { if (parseInt(userCard.substr(16, 1)) % 2 == 1) { return "男"; } else { return "女"; } } //获取年龄 if (num == 3) { var myDate = new Date(); var month = myDate.getMonth() + 1; var day = myDate.getDate(); var age = myDate.getFullYear() - UUserCard.substring(6, 10) - 1; if (userCard.substring(10, 12) < month || userCard.substring(10, 12) == month && userCard.substring(12, 14) <= day) { age++; } return age; } }
标签:10,12,身份证号,userCard,substring,num,js,性别 From: https://www.cnblogs.com/liweimingbk/p/17184927.html