根据用户输入身份证号前端自动计算其年龄
作者:互联网
前端
function get_baseinfo() {
var usercode = $('#usercode').val();if (usercode == '' || usercode.length != 18) {
alert('请输入18位正确身份证号');
return false;
}
var date = new Date();
var year = date.getFullYear();
var birthday_year = parseInt(usercode.substr(6, 4));
var userage = year - birthday_year;
$('#age').val(userage);
return false;
}
<input type="text" id="usercode" οnchange="get_baseinfo()" name="identity" required="required" data-validate-length-range="8,20" class="form-control col-md-7 col-xs-12">
<input type="text" id="age" name="age" readonly="readonly" required="required" data-validate-length-range="8,20" class="form-control col-md-7 col-xs-12">
标签:false,val,usercode,前端,身份证号,year,var,return,输入 来源: https://blog.51cto.com/u_13993537/2991659