本文实例为大家讲述了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程序设计有所帮助。