日期:2014-05-16  浏览次数:20325 次

对字符串进行编辑
对字符串进行编辑···在textfield输入 1的时候··失去焦点后更新为 01.00···1.5更新为01.50···输入的数值部超过24··

------解决方案--------------------

function format(arg){
            var tmp,result = '';
            if(typeof arg !== 'undefined' && typeof parseFloat(arg) === 'number' && parseFloat(arg).toString() !== 'NaN'){
                if(parseFloat(arg) >= 24)
                    return "24.00";
                arg = parseInt(arg*100) / 100;
                tmp = arg.toString().split('.');
                if(tmp.length === 1){
                    if(tmp[0].length === 1){
                        tmp[0] = "0" + tmp[0];
                    }
                    return tmp[0] + '.00';
                }
                else{
                    if(tmp[0].length === 1){
                        result += "0" + tmp[0] + '.';
                    }else{
                        result += tmp[0] + ".";
                    }
                    if(tmp[1].length === 1){
                        result += tmp[1] + '0';
                    }else{
                        result += tmp[1];
                    }
                    return res