JS 输入银行卡号,4位自动加空格

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
<html>  
<head>  
  
    <title>test</title>  
    <script type="text/javascript">  
        window.onload =function() {  
            document.getElementById("test").onkeyup =function() {  
                this.value =this.value.replace(/\s/g,'').replace(/(\d{4})(?=\d)/g,"$1 ");;  
            };  
        };  
    </script>  
</head>  
<body>  
    <input type="text" id="test"/>  
</body>  
</html>  
posted @ 2012-06-29 17:04  上善若水.  阅读(2754)  评论(0编辑  收藏  举报