本文實例為大家講述了js實現根據身份證號自動生成出生日期的代碼,分享給大家供大家參考,具體內容如下
運行效果圖:
<!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程序設計有所幫助。