js实现根据身份证号自动生成出生日期

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

js实现根据身份证号自动生成出生日期

温暖的小朋   2020-05-14 我要评论

本文实例为大家讲述了js实现根据SFZ号自动生成出生日期的代码,分享给大家供大家参考,具体内容如下

运行效果图:


<!doctype>
<html>
<head>
  <script type="text/javascript">
  function dealCard(){
    var birthday=getBirthday();
    switch(birthday){
      case 0:alert("Sorry,the program runs wrong!");break;
      case 1:alert("You must be input again!");break;
      default: alert("the birthday is"+birthday);break;
    }  
  }
  function getBirthday(){
    var a=document.getElementById("card").value;
    if(15==a.length || 18==a.length){
      var left=a.length-12;
      var right=a.length-4;
      var b=a.slice(left,right);
      if(8==b.length){
        return b;
      }
      else return 0;
    }
    else return 1;
  }
  </script>
</head>
<body>
  input <input type="text" id="card" height=20px width=40px/>
  <br/>
  <button type="button" onclick="dealCard()">please click it</button>
</body>
</html>

代码直接复制即可运行哦!

希望本文所述对大家学习javascript程序设计有所帮助。

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们