vue+element-ui项目表单中输入身份证号码,自动返回性别和年龄

我写出来的效果(禁用了性别的单选按钮和年龄的输入框)
vue+element-ui项目表单中输入身份证号码,自动返回性别和年龄_第1张图片
html部分

 
     
 

 
     
         
         
     
 

 
     
 

逻辑部分(methods里边)

 getName(iden){
            let val = iden.length;
            let sex = null;
            let myDate = new Date();
            let month = myDate.getMonth() + 1;
            let day = myDate.getDate();
            let age = 0;
    
            if(val===18){
            age = myDate.getFullYear() - iden.substring(6, 10) - 1;
            sex = iden.substring(16,17);
            if (iden.substring(10, 12) < month || iden.substring(10, 12) == month && iden.substring(12, 14) <= day) age++;
    
            }
            if(val===15){
            age = myDate.getFullYear() - iden.substring(6, 8) - 1901;
            sex = iden.substring(13,14);
            if (iden.substring(8, 10) < month || iden.substring(8, 10) == month && iden.substring(10, 12) <= day) age++;
            }
    
            if(sex%2 === 0)
            sex = 1
            else
            sex = 0
            this.ruleForm.sex = sex;
            this.ruleForm.age = age;

            this.getDataInfo();
        },

需要的同胞,直接拷过改改吧,都不容易

你可能感兴趣的:(vue,element-ui,vue+element-ui,身份证信息带出性别年龄)