本文实例为大家讲述了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程序设计有所帮助。
标签:
js,身份证号,出生日期
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“js实现根据身份证号自动生成出生日期”评论...
