Html代码

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

 <input type="text" >
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*/, '');   

            });   

        };  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2021-08-01
  • 2021-08-01
  • 2021-08-01
猜你喜欢
  • 2021-08-01
  • 2021-06-12
  • 2021-06-15
  • 2022-12-23
  • 2021-08-01
  • 2021-08-01
  • 2021-11-28
相关资源
相似解决方案