好像这句的问题
txt.onpropertychange = function () {this.value = this.value.replace(/[^0-9.-]/g,"");};

解决方案 »

  1.   

    修改后的代码为function onlyNumber(id)
    {
        var txt = $(id);
        if (txt == null) return; 
        
        //txt.onpropertychange = function () {this.value = this.value.replace(/[^0-9.-]/g,"");};
        
        txt.onpropertychange = function () {
         if(!/[^0-9.-]/.test(this.value)) return false;
         this.value = this.value.replace(/[^0-9.-]/g,"");
        };
    }