漫天 flurrying

漫天 Asp.net C# flurrying 程序员 SEO asp java jsp javascript
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

jQuery EasyUI 数字框(NumberBox)用法

Posted on 2010-07-08 10:49  漫天  阅读(5874)  评论(2编辑  收藏  举报

jquery-easyui-jqnumber 

 

这里的options是选项,可以参考下表:

选项名 类型 描述 默认值
min 数字 文本框中可允许的最小值 null
max 数字 文本框中可允许的最大值 null
precision 数字 最高可精确到小数点后几位 0

 

例如:金额输入框 最大值为“99999.99” 精确到两位小数。

<input name="money" id="money" type="text" class="easyui-numberbox" precision="2" max="99999.99" size="8" maxlength="8"  style="text-align:right;"/>

 

如果是动态的input 加载的时候会有问题。

解决方法:

       动态载入/删除/更新外部 JavaScript/Css 文件

加载动态的input后,更新一下jquery.easyui.min.js文件。就相当于重新加载一次jquery.easyui.min.js文件。

 

 

 

另转一个 JQuery 验证表单只能输入数字 支持火狐

$.fn.numeral = function() {  
            $(this).css("ime-mode", "disabled");  
            this.bind("keypress",function(e) {  
            var code = (e.keyCode ? e.keyCode : e.which);  //兼容火狐 IE   
                if(!$.browser.msie&&(e.keyCode==0x8))  //火狐下 不能使用退格键  
                {  
                     return ;  
                    }  
                    return code >= 48 && code<= 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*/, '');  
                }  
            });  
        };  

 

使用方法 $("#txt1").numeral();