源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-07-30 02:31 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:js实现根据身份证号自动生成出生日期
本文实例为大家讲述了js实现根据身份证号自动生成出生日期的代码,分享给大家供大家参考,具体内容如下 运行效果图: [img]http://files.jb51.net/file_images/article/201512/20151215112027540.jpg?20151115112039[/img]
<!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程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部