试着自己写一下,就会了
<!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>
<!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>
解决方案 »
- out print(); 无法使用!留言本里面的内容如何换行 急急急。。。。[
- valueof tostring 同时用的疑惑
- 用什么工具对script进行格式化?
- 关于span嵌套的问题
- 含有文件路径属性的标签有哪些?比如A、IMG INPUT等。哪里有完整的吗?
- 这样的xml文件,如何用js往里面插入一条记录和删除一条以及更新一条记录,请各位多多帮忙。
- 如何将汉字转化为16进制数
- 100分高手请指教:Netscape4.X和javascript难题!
- 同步服务器和客户机时间
- 小白请教: form.id.value = array[2] 这样赋值除了可以在input中,还可以在什么里面?
- <a href="#MiaoDian1" ID="hrefValue" name="hrefValue">查看</a> 怎么用javascript 代替单击?
- 在线等 缩略图问题
{
var birthdayValue;
if(15==val.length)
{ //15位身份证号码
birthdayValue = val.charAt(6)+val.charAt(7);
if(parseInt(birthdayValue)<10)
{
birthdayValue = '20'+birthdayValue;
}
else
{
birthdayValue = '19'+birthdayValue;
}
birthdayValue=birthdayValue+'-'+val.charAt(8)+val.charAt(9)+'-'+val.charAt(10)+val.charAt(11);
if(parseInt(val.charAt(14)/2)*2!=val.charAt(14))
document.all.sex.value='男';
else
document.all.sex.value='女';
document.all.birthday.value=birthdayValue;
}
if(18==val.length)
{ //18位身份证号码
birthdayValue=val.charAt(6)+val.charAt(7)+val.charAt(8)+val.charAt(9)+'-'+val.charAt(10)+val.charAt(11) +'-'+val.charAt(12)+val.charAt(13);
if(parseInt(val.charAt(16)/2)*2!=val.charAt(16))
document.all.sex.value='男';
else
document.all.sex.value='女';
if(val.charAt(17)!=IDCard(val))
{
document.all.idCard.style.backgroundColor='#ffc8c8';
}
else
{
document.all.idCard.style.backgroundColor='white';
}
document.all.birthday.value=birthdayValue;
}
} // 18位身份证号最后一位校验
function IDCard(Num)
{
if (Num.length!=18)
return false;
var x=0;
var y=''; for(i=18;i>=2;i--)
x = x + (square(2,(i-1))%11)*parseInt(Num.charAt(19-i-1));
x%=11;
y=12-x;
if (x==0)
y='1';
if (x==1)
y='0';
if (x==2)
y='X';
return y;
} // 求得x的y次方
function square(x,y)
{
var i=1;
for (j=1;j<=y;j++)
i*=x;
return i;
}
</script>
http://topic.csdn.net/u/20081111/11/4d1e42a8-8749-40ec-a215-bea9229b7374.html?56860247
<!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>