日期:2014-05-16  浏览次数:20431 次

输入身份证号,自动显示生日
<input   name= "news_identcard "   type= "text "   class= "myinput "   id= "news_identcard "   value= " "   size= "18 "   maxlength= "18 ">

鼠标离开这个input后

出生年月框,自动显示年月

------解决方案--------------------
...........
所有的大陆居民身份证 的出身日期都是从第6位开始的.......
先来了解一下身份证的标准
----------------------------------------------
身份证原有的15位号码在升18位时基本不变,只是在出生年前加两位(例如王先生是1975年出生的,他的身份证号码是132826750111161, 其中132826为区位码,75代表1975年出生,升为18位后将改为1975,即在75前加19,将出生年补充完整);另外在身份证号码末位后再补充一位数字,这位数字是随机的,因而不再具有其他意义,仅用于识别.(原来的身份证号码末位单数代表男性,偶数代表女性.上面讲到的王先生升位前身份证号码末位是1,是单数,代表男性,而升位后身份证号码变为132826197501111618,末位是8变为了偶数.)部分人的身份证升为18位后末位还会出现X这个字母,而不是数字.这都是很正常的.
----------------------------------------------

<script type= "text/javascript ">
var str1= "132826750111161 ";
var str2= "522512198512122134 ";
document.write(str1.substring(6,6)) ; <!--15位-->
document.write(str2.substring(6,8)) ; <!--18位-->
</script>


一个字符串函数就搞定了啊!!!
SubString()


------解决方案--------------------
上面的写错了。。。。。。。。。。。

代码如下:

<!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=gb2312 " />
<title> 无标题文档 </title>
<script type= "text/javascript ">
function test()
{
var aaa;
aaa = document.getElementById( "num ");
if(aaa.value.length == 15)
{
alert(aaa.value.substring(6,12));
}
else if(aaa.value.length == 18)
{
alert(aaa.value.substring(6,14));
}

}
</script>


</head>
<body>
<input id= "num " name= "num " value= " " onblur= "test() "/>
</body>
</html>

stringObject.substring(start,stop)

start
开始位置 Required. Where to start the extraction. Must be a numeric value
必选项。开始选取的位置。必须为数字。
stop
停止 Optional. Where to stop the extraction. Must be a numeric value
可选项。停止选取的位置。必须为数字。

------解决方案--------------------
lenber() 提供的信息完全正确...

<pre>
所有的大陆居民身份证 的出身日期都是从第6位开始的.......
先来了解一下身份证的标准
----------------------------------------------
身份证原有的15位号码在升18位时基本不变,只是在出生年前加两位(例如王先生是1975年出生的,
他的身份证号码是132826750111161, 其中132826为区位码,75代表1975年出生,升为18位后将改为1975,
即在75前加19,将出生年补充完整);另外在身份证号码末位后再补充一位数字,这位数字是随机的,
因而不再具有其他意义,仅用于识别.(原来的身份证号码末位单数代表男性,偶数代表女性.上面讲到的王先生升位前身份证号码末位是1,是单数,代表男性,
而升位后身份证号码变为132826197501111618,
末位是8变为了偶数.)部分人的身份证升为18位后末位还会出现X这个字母,而不是数字.这都是很正常的.
</pre>

<script type= "text/javascript ">
// <![CDATA[
var IdFt = "445121820929367 ";
var IdSt = "445121198209293677 ";
var IdSt1 = "445121198209293677x ";

document.write(fGetBirthDayById(IdFt, false, true), " <hr/> ");
document.write(fGetBirthDayById(IdFt, true, true).toLocaleDateString(), " <hr/> ");

document.write(fGetBirthDayById(IdSt, false, true), " <hr/> ");
document.write(fGetBirthDayBy