var cardId=$("#cardId").val();//先获取身份证号(据自己实际写法获取)
1、获取出生日期:
function getBirth(cardId){
var birth=cardId.substring(6, 10) + "-" + cardId.substring(10, 12) + "-" + cardId.substring(12, 14);
return birth;
}
2、获取性别:
function getSex(cardId){
if (parseInt(cardId.substr(16, 1)) % 2 == 1) {
return '男';
} else {
return '女';
}
}
3、获取年龄:
function getAge(cardId){
var myDate = new Date();
var month = myDate.getMonth() + 1;
var day = myDate.getDate();
var age = myDate.getFullYear() - cardId.substring(6, 10) - 1;
if (cardId.substring(10, 12) < month || cardId.substring(10, 12) == month && cardId.substring(12, 14) <= day) {
age++;
}
return age;
}