jquery银行卡输入控件使用

jquery.bankInput.js

/** 
× JQUERY 模拟淘宝控件银行帐号输入 
**/ 
(function($){ 
    // 输入框格式化 
    $.fn.bankInput = function(options){ 
        var defaults = { 
            min : 16, // 最少输入字数 
            max : 25, // 最多输入字数 
            deimiter : ' ', // 账号分隔符 
            onlyNumber : true, // 只能输入数字 
            copy : false // 允许复制 
        }; 
        var opts = $.extend({}, defaults, options); 
        var obj = $(this); 
        obj.css({imeMode:'Disabled',borderWidth:'1px',color:'#000',fontFamly:'Times New Roman'}).attr('maxlength', opts.max); 
        if(obj.val() != '') obj.val( obj.val().replace(/\s/g,'').replace(/(\d{4})(?=\d)/g,"$1"+opts.deimiter) ); 
        obj.bind('keyup',function(event){ 
            if(opts.onlyNumber){ 
                if(!(event.keyCode>=48 && event.keyCode<=57)){ 
                    this.value=this.value.replace(/\D/g,''); 
                } 
            } 
            this.value = this.value.replace(/\s/g,'').replace(/(\d{4})(?=\d)/g,"$1"+opts.deimiter); 
        }).bind('dragenter',function(){ 
            return false; 
        }).bind('onpaste',function(){ 
            return !clipboardData.getData('text').match(/\D/); 
        }).bind('blur',function(){ 
            this.value = this.value.replace(/\s/g,'').replace(/(\d{4})(?=\d)/g,"$1"+opts.deimiter); 
            if(this.value.length < opts.min){ 
                //alertMsg.warn('最少输入'+opts.min+'位账号信息!'); 
                obj.focus(); 
            } 
        }) 
    } 
    // 列表显示格式化 
    $.fn.bankList = function(options){ 
        var defaults = { 
            deimiter : ' ' // 分隔符 
        }; 
        var opts = $.extend({}, defaults, options); 
        return this.each(function(){ 
            $(this).text($(this).text().replace(/\s/g,'').replace(/(\d{4})(?=\d)/g,"$1"+opts.deimiter)); 
        }) 
    } 
})(jQuery); 

使用方法

1.默认使用方法: 
$("#account").bankInput(); 
2.设置参数 
$("#account").bankInput({min:16,max:25,deimiter,' '}); 
3.非文本框格式化显示 
$(".account").bankList(); 

测试案例

<!doctype html>
<html lang="cn">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
    <script src="jquery.bankInput.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $('#account1').bankInput(); 
            $('#account2').bankInput({min:4,max:25,deimiter:','}); 
            $('#account3').bankList(); 
        })
    </script>
</head>
<body>
    帐号1:<input id="account1"/><br/>
帐号2:<input id="account2"/><br/>
帐号3:<input id="account3"/><br/>

</body>
</html>

参考出处
http://www.thinksaas.cn/group/topic/41340/

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值