<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input type="text" type="number" name="" id="card" onkeyup="ck(this)" onKeyDown="del(this)">
<br>
<input type="text" id="show">
</body>
<script type="text/javascript">
var card=''
function ck(e) {
if(e.value.length>card.length){
card=card+e.value.slice(-1)
e.value=e.value.slice(0,-1)+"*"
}
l=e.value.length+1
if(!(l%5)){
e.value=e.value+" "
card=card+" "
}
document.getElementById('show').value=card
}
function del (e) {
if(event.code=="Backspace"){
if(e.value.slice(-1)==" "){
e.value=e.value.slice(0,-1)
card=card.slice(0,-1)
}
card=card.slice(0,-1)
}
}
</script>
</html>
输的太快会出问题
var num1 = 74000001
var stt = num1.replace("/(.{4})", "$1 ")
//显示出来的字符串 比如 银行卡号一样的
console.log("stt",stt)