码迷,mamicode.com
首页 > Web开发 > 详细

JS input 银行卡号格式转换

时间:2017-11-07 17:49:57      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:enter   log   news   var   eve   center   input   margin   function   

传送门:http://demo.sc.chinaz.com//Files/DownLoad/webjs1/201411/jiaoben2920/

 

<!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="">

<div style="text-align:center;margin:50px 0; font:normal 14px/24px ‘MicroSoft YaHei‘;">
<p>适用浏览器:IE8、360、FireFox、Chrome、Safari、Opera、傲游、搜狗、世界之窗. </p>
<p>来源:<a href="http://sc.chinaz.com/" target="_blank">站长素材</a></p>
</div>
</body>
</html>

 

JS input 银行卡号格式转换

标签:enter   log   news   var   eve   center   input   margin   function   

原文地址:http://www.cnblogs.com/CyLee/p/7799376.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!