• vue 根据输入的身份号码,自动获取年龄


    身份证号:
     
    • 年龄:

        getName(iden) {
              let val = iden.length;
              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;
      
                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;
      
                if (iden.substring(8, 10) < month || iden.substring(8, 10) == month && iden.substring(10, 12) <= day) age++;
              }
      
              this.age = age;
      
            },
      

        

        <li>
              <form label="身份证号" prop="idCard">
                <span>身份证号:</span>
                <input v-model="idCard" placeholder="请输入身份证号" @blur="getName(idCard)" class="input" tyle="text"></input>
                <div style="clear:both;"></div>
              </form>
            </li>
      
            <li>
              <form label="年龄" prop="age">
                <span>年龄:</span>
                <input v-model="age" placeholder="年龄"  class="input"></input>
                <div style="clear:both;"></div>
              </form>
            </li>
      

        

  • 相关阅读:
    css基础属性
    选择器的类型
    css的三种表现形式
    表单和表格
    如何比较两个xml 的异同
    xslt 简单的语法
    xslt 和一个demo
    event based xml parser (SAX) demo
    SAX vs. DOM (Event vs. Tree)
    xmlns 实例分析
  • 原文地址:https://www.cnblogs.com/xzhce/p/13064591.html
Copyright © 2020-2023  润新知