<script>
function getAge(){
var aDate=new Date();
var thisYear=aDate.getYear();
var brith=document.getElementById("date1").value;
brith=brith.substr(0,4);
age=(thisYear-brith);
document.getElementById("date2").value=age;
}
function ExtractionBirthday(oneText,twoText){
var txtparm = document.getElementById(oneText).value;
if(txtparm.length==18){
var year = txtparm.substring(6,10);
var month = txtparm.substring(10,12);
var date=txtparm.substring(12,14);
document.getElementById(twoText).value=year+"-"+month+"-"+date;
}else{
alert("输入的身份证不正确!");
document.getElementById(oneText).focus();
document.getElementById(oneText).value="";
}
}
</script>
<from name="theform">
生日:<input name="date1" id="date1" onblur="getAge()">
年龄:<input name="date2" id="date2">
身份证:<input id="A" type="text" onblur="ExtractionBirthday('A','B');"/>
出生日期:<input id="B" type="text"/>
</form></font>