日期:2008-08-17  浏览次数:21452 次

//判断是否是日期型数据
function isDate(dateVal)
{
    var a1=dateVal.replace(/-/g,"/");

    var dd=new Date(a1);
    var ss=dd.getYear();
    if(isNaN(ss))
        return false;
    else
        return true;
}

//保留小数点精度,发现有些版本比较低的IE用不了toFixed函数,才写了这个
//oldData:原数据
//precision:精度
function toFixedFunc(oldData,precision)
{
    if(oldData.indexOf(".")>=0)
    {
        var diff=oldData.length-(oldData.lastIndexOf(".")+1)
        if(diff<=precision)
        {
            for(var i=0;i<precision-diff;i++)
                oldData=oldData+"0";
        }
        else
        {
            //四舍五入
            oldData=oldData.substring(0,oldData.indexOf(".")+1+precision+1);
            var lastNum=parseInt(oldData.substring(oldData.length-1,oldData.length));
            oldData=oldData.substring(0,oldData.length-1);
            if(lastNum>=5)
            {
                var newData=parseInt(oldData.substring(0,oldData.indexOf("."))+oldData.substring(oldData.indexOf(".")+1,oldData.length));
                newData=newData+1;
                oldData=newData.toString();
                oldData=oldData.substring(0,oldData.length-precision)+"."+oldData.substring(oldData.length-precision,oldData.length);
            }
        }
    }
    else
    {
        oldData=oldData+".";
        for(var i=0;i<precision;i++)
            oldData=oldData+"0";
    }
    return oldData;
}

//去掉空格
//oldStr:原数据
//place:left,right,为空的话去掉左右空格
function trim(oldStr,place)
{
    if(place=="left")
        newStr=lTrim(oldStr);
    if(place=="right")
        newStr=rTrim(oldStr);
    if(plac