<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;
}
</script>
<from name="theform">
生日:<input name="date1" id="date1" onblur="getAge()">
年龄:<input name="date2" id="date2">
</form>
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;
}
</script>
<from name="theform">
生日:<input name="date1" id="date1" onblur="getAge()">
年龄:<input name="date2" id="date2">
</form>