jquery

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<input type="text" />
<script src="http://static.dtao.org/libs/jquery/1.11.2/jquery.js"></script>
<script>
    !function () {
        $('#J_BankCard').on('keyup mouseout input',function(){
            var $this = $(this),
                v = $this.val();
            /\S{5}/.test(v) && $this.val(v.replace(/\s/g,'').replace(/(.{4})/g, "$1 "));
        });
    }();
</script>
</body>
</html>

原生

!function () {
    document.getElementById('bankCard').onkeyup = function (event) {
        var v = this.value;
        if(/\S{5}/.test(v)){
            this.value = v.replace(/\s/g, '').replace(/(.{4})/g, "$1 ");
        }
    };
}();

转自:http://www.dtao.org/archives/472

相关文章:

  • 2022-12-23
  • 2022-02-07
  • 2021-06-05
  • 2022-12-23
  • 2021-12-13
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案