Home > Web Front-end > JS Tutorial > js to automatically generate date of birth based on ID number_javascript skills

js to automatically generate date of birth based on ID number_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 15:25:37
Original
1588 people have browsed it

The example in this article tells you about the js implementation of the code to automatically generate the date of birth based on the ID number, and shares it with you for your reference. The specific content is as follows

Operation rendering:


<!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>
Copy after login

Copy the code directly and run it!

I hope this article will be helpful to everyone in learning javascript programming.

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Where is js written?
From 1970-01-01 08:00:00
0
0
0
js file code not found
From 1970-01-01 08:00:00
0
0
0
js addClass not working
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template