zoukankan      html  css  js  c++  java
  • 根据身份证号 获取生日、年龄和性别

     //根据身份证获取年龄和性别
        function analyzeIDCard(obj) {
            //console.log('123')
            var IDCard = $(obj).val();
            var birth = IDCard.substring(6, 10) + "-" + IDCard.substring(10, 12) + "-" + IDCard.substring(12, 14);
            //console.log(birth);
            var sex = "";
            if (parseInt(IDCard.substr(16, 1)) % 2 == 1) {
                sex = "男";
            } else {
                sex = "女";
            }
            //console.log(sex);
            //获取年龄
            var myDate = new Date();
            var month = myDate.getMonth() + 1;
            var day = myDate.getDate();
            var age = myDate.getFullYear() - IDCard.substring(6, 10) - 1;
            if (IDCard.substring(10, 12) < month || IDCard.substring(10, 12) == month && IDCard.substring(12, 14) <= day) {
                age++;
            }
            //console.log(age);
            $("#Age").val(age);
    
            if (sex == "男")
                $("input[name=Sex][value=true]").prop("checked", true);
            else
                $("input[name=Sex][value=false]").prop("checked", true);
        }
  • 相关阅读:
    php apc
    nginx https
    js弹出确认框,挺全
    websocket nodejs
    nodejs express测试
    【C++】Mandelbrot集绘制(生成ppm文件)
    【Scheme】Huffman树
    【Scheme】符号求导
    【Scheme】树结构
    【Scheme】序列的操作
  • 原文地址:https://www.cnblogs.com/Leeblog200814/p/15517522.html
Copyright © 2011-2022 走看看