如何通过身份证来识别年龄呢?我提供了以下方法,经供参考:
html
<input type="text" id="peiouIdno" />
<input type="text" id="peiouAge" />
<button type="button" onclick="getYear();">获取年龄</button>
JS
function getYear(){
var UUserCard = $("#peiouIdno").val();
if(UUserCard != null && UUserCard != ''){
//获取年龄
var myDate = new Date();
var month = myDate.getMonth() + 1;
var day = myDate.getDate();
var age = myDate.getFullYear() - UUserCard.substring(6, 10) - 1;
if (UUserCard.substring(10, 12) < month || UUserCard.substring(10, 12) == month && UUserCard.substring(12, 14) <= day) {
age++;
}
$("#peiouAge").val(age);
}
else{
$("#peiouAge").val("");
}
}