//根据身份证取 省份,生日,性别
function getInfo() {
//获取输入身份证号码
var ic = $("#txtCardID").val();
ic = checkId(ic);
if (isNaN(ic)) return;
var ic = String(ic);
//获取出生日期
var birth = ic.substring(6, 10) + "-" + ic.substring(10, 12) + "-" + ic.substring(12, 14);
//获取性别
var gender = ic.slice(14, 17) % 2 ? "1" : "2"; // 1代表男性,2代表女性
var sexOption = document.getElementsByName("rabSex");
for (var i = 0; i < sexOption.length; i++) {
if (sexOption[i].value == gender) {
sexOption[i].checked = true;
break;
}
}
//获取年龄
var myDate = new Date();
var month = myDate.getMonth() + 1;
var day = myDate.getDate();
var age = myDate.getFullYear() - ic.substring(6, 10) - 1;
if (ic.substring(10, 12) < month || ic.substring(10, 12) == month && ic.substring(12, 14) <= day) {
age++;
}
$("#txtAge").val(age);
}
转载于:https://www.cnblogs.com/SeaWxx/p/7988243.html