html中出生日期内容在输入身份证号码后自动生成,与身份证号一一对应,不能单独修改

解决方案 »

  1.   


    <!DOCTYPE HTML>
    <html>
    <head>
    <meta charset="gb2312" />
    <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);
    }
    }
    </script>
    </body>
    </html>