Home > Web Front-end > JS Tutorial > Implementing gender and age identification based on ID number based on javascript_javascript skills

Implementing gender and age identification based on ID number based on javascript_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 15:19:00
Original
1868 people have browsed it

This article introduces the detailed code of javascript to identify gender and age based on ID number. It is shared with everyone for your reference. The specific content is as follows

Rendering:

Specific code:

<html>
<head>
<meta charset="gb2312">
<title>jb51</title>
<script type="text/javascript"> 
function discriCard(UUserCard)
{ 
 UUserCard.substring(6,10)+"-"+UUserCard.substring(10,12)+"-"+UUserCard.substring(12,14); 
 //获取性别 
 if(parseInt(UUserCard.substr(16,1))%2==1) 
 { 
  alert("男"); 
  //是男则执行代码 ... 
 } 
 else 
 { 
  alert("女"); 
  //是女则执行代码 ... 
 } 
 //获取年龄 
 var myDate = new Date(); 
 var month = myDate.getMonth() + 1; 
 var day = myDate.getDate(); 
 var age = myDate.getFullYear()-UUserCard.substring(6, 10) - 1; 
 if (UUserCard.substring(10,12)<month||UUserCard.substring(10,12)==month&&UUserCard.substring(12,14)<=day) 
 { 
  age++; 
 } 
 alert(age); 
 //年龄 age 
} 
window.onload=function()
{
 var txt=document.getElementById("txt");
 var bt=document.getElementById("bt");
 bt.onclick=function(){discriCard(txt.value);}
}
</script>
</head>
<body>
<input type="text" id="txt" />
<input type="button" value="点击获取信息" id="bt" />
</body>
</html>
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone in learning javascript programming.

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
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
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