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 the code directly and run it!
I hope this article will be helpful to everyone in learning javascript programming.