87,914
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
身份证:<input type="text" id="sfz" onblur="fun()"/>
生日:<input type="text" id="sr" />
性别:
<select id="sex">
<option>男</option>
<option>女</option>
</select>
<script type="text/javascript">
function fun()
{
var sfz = document.getElementById("sfz");
var sr = document.getElementById("sr");
var sex = document.getElementById("sex");
if(sfz.value.length!=18 && sfz.value.length!=15)
{
alert("生日错误");
return;
}
var birthday;
var sexflag;
if(sfz.value.length==18)
{
birthday = sfz.value.substring(6,14);
sexflag = sfz.value.substring(14,17).replace(/^0*/,"");
}
else
{
birthday = "19"+sfz.value.substring(6,12);
sexflag = sfz.value.charAt(14);
}
sr.value = birthday.replace(/(\d{4})(\d{2})(\d{2})/,"$1年$2月$3日");
var s = sexflag.replace(/^0*/,"");
if( parseInt(s,10)%2==0 )
sex.selectedIndex = 1;
else
sex.selectedIndex = 0;
}
</script>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
身份证:<input type="text" id="sfz" onblur="fun()"/>
生日:<input type="text" id="sr" />
性别:
<select id="sex">
<option>男</option>
<option>女</option>
</select>
<script type="text/javascript">
function fun()
{
var sfz = document.getElementById("sfz");
var sr = document.getElementById("sr");
var sex = document.getElementById("sex");
if(sfz.value.length!=18)
{
alert("生日错误");
return;
}
sr.value = sfz.value.substring(6,14).replace(/(\d{4})(\d{2})(\d{2})/,"$1年$2月$3日");
var s = sfz.value.substring(14,17).replace(/^0*/,"");
if( parseInt(s,10)%2==0 )
sex.selectedIndex = 1;
else
sex.selectedIndex = 0;
}
</script>
</body>
</html>