<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<title>输入身份证自动生成出生日期</title>
<style>
</style>
</head>
<body>
<label for="sfz">身份证:</label>
<input id="sfz" maxlength="18" />
出生年月<input id="birthday" readonly="readonly" />
<script>
function $(o){return document.getElementById(o)}
var re = /^\d{17}[\dxX]$/;
$('sfz').onkeyup = function(){
var s = this.value;
if( s.length == 18 ){
$('birthday').value = s.substring(6,10) + '-' + s.substring(10,12) + '-' + s.substring(12,14);
}else if(s.length == 15){
$('birthday').value = 19+s.substring(6,8) + '-' + s.substring(8,10) + '-' + s.substring(10,12);
}
}
</script>
</body>
</html>