zoukankan      html  css  js  c++  java
  • js控制文本栏只能输入数字

    Html代码

     <input type="text" id="txt1">  

     <input type="text" id="txt1">
    Html代码

    <script type="text/javascript">  

    $("#txt1").numeral();   

    </script>  

    <script type="text/javascript">  $("#txt1").numeral(); </script>
    Js代码

    $.fn.numeral = function(){   

                $(this).css("ime-mode","disabled");   

                this.bind("keypress",function(){   

                    if(event.keyCode == 46){   

                        if(this.value.indexOf(".")!=-1){   

                           return false;   

                        }   

                    }else{   

                        return event.keyCode>=46&&event.keyCode<=57;   

                    }   

                });   

                this.bind("blur",function(){   

                    if(this.value.lastIndexOf(".")==(this.value.length-1)){   

                        this.value = this.value.substr(0,this.value.length-1);   

                    }else if(isNaN(this.value)){   

                        this.value = "";                       

                    }   

                });   

                this.bind("paste",function(){   

                    var s=clipboardData.getData('text');    

                    if(!/\D/.test(s));    

                    value=s.replace(/^0*/,'');    

                    return false;   

                });   

                this.bind("dragenter",function(){   

                    return false;   

                });   

                this.bind("keyup",function(){   

                    if(/(^0+)/.test(this.value))this.value=this.value.replace(/^0*/, '');   

                });   

            };  

  • 相关阅读:
    SEO分享:我为什么会有这么多的优质外链资源?
    执行shell脚本提示“syntax error near unexpected token for((i=0;i&lt;$length;i++))”
    Codeforces Round #254 (Div. 2)D(预计)
    自己写配置文件
    软件測试基本方法(二)之白盒測试
    hdu 4638 Group
    影视集结号--首页
    2015阿里巴巴秋招在线笔试题
    php 抓取天气情况 www.weather.com.cn
    C语言中的enum(枚举)使用方法
  • 原文地址:https://www.cnblogs.com/linzheng/p/1853576.html
Copyright © 2011-2022 走看看