以下是 js银行卡号格式输入框特效代码 的示例演示效果:
部分效果截图:
HTML代码(index.html):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>js银行卡号格式输入框</title>
<style>
*{margin:0;padding:0;}
input{margin:100px auto;display:block;border:1px solid #000;width:200px;height:30px;line-height:30px;}
</style>
<script>
window.onload=function()
{
var oT=document.getElementById('text');
oT.onkeydown=function(ev)
{
var oW=oT.value;
var oEvent=ev||event;
if(oEvent.keyCode==8)
{
if(oW)
{
for(var i=0;i<oW.length;i++)
{
var newStr=oW.replace(/\s$/g,'');
}
oT.value=newStr
}
}else{
for(var i=0;i<oW.length;i++)
{
var arr=oW.split('');
if((i+1)%5==0)
{
arr.splice(i,0,' ');
}
}
oT.value=arr.join('');
}
}
}
</script>
</head>
<body>
<input id="text" type="text" value="">
</body>
</html>