//document.domain = "jrj.com.cn"; function $(element) { if (typeof(element) == "string"){ element = document.getElementById(element); } return element; } function Trim(strSource) { return strSource.replace(/^\s*/,'').replace(/\s*$/,''); } function ChkCZDate(edit){ edit.value=Trim(edit.value); if(edit.value=='') return true; if(!Cal_datevalid(edit,'1910-1-1','3000-1-1')) { alert('日期格式不正确,日期有效范围为1910年到3000年'); edit.focus(); } } var maxfn=99999999.9; var maxpn=99999999; var overerrormsg="数值超过最大值99999999"; /*函数:检验字段是否为空 输入:objArray(数组类型,其中各元素为需要检验的表单内文本对象) 输出:若为空则弹出警告信息,焦点集中在为空的输入框内,并返回值:false 全不为空则返回值:true **/ function checkData(objArray){ var textnow; var rst="true"; for(i=0;i=0 )||(temp!=s)) { result=false; } else if ( (!IsCanZero)&&(temp==0) ) { result=false; } if (temp>maxpn) { result=false; disptext=overerrormsg; } if (!result) { if (page) showguide(page); DispMessage(CheckCtl, disptext); return false; } return true; } /*功能:校验一个合法的大于等于0的浮点数 入口参数: CheckCtl: 要校验的输入框 disptext: 出错显示的信息 floatcount: 小数的最高位数(如果没有该参数,则默认为2位) 如果没有page参数,有floatcunt参数则:把page 置null 如: CheckFN(CheckCtl,"出错显示的信息",null,5) */ function CheckFN(CheckCtl,disptext,page,floatcount){ var s=new String(Trim(CheckCtl.value)); temp=parseFloat(s); var result=true; if( (isNaN(temp)) || (temp< 0)||(temp!=s) ){ result=false; } else if (temp>maxfn) { result=false; disptext=overerrormsg; } else { limitcount=floatcount?floatcount:2; var array=s.split("."); if (array[1]==null) count=-1; else{ var str=new String(array[1]); count=str.length; } if (count>limitcount){ if (page) showguide(page); alert("小数位数超过"+limitcount+"位"); CheckCtl.select(); CheckCtl.focus(); return false; } } if (!result){ if (page) showguide(page); DispMessage(CheckCtl,disptext); return false; } return true; } function CheckFN2(CheckCtl,disptext,page,floatcount){ return CheckFN(CheckCtl,disptext,page,floatcount); } function CheckFN3(CheckCtl,disptext,IsCanZero,page,floatcount){ if ( CheckFN(CheckCtl,disptext,page,floatcount) ){ if ( (parseFloat(CheckCtl.value)==0) &&(!IsCanZero) ){ if (page) showguide(page); DispMessage(CheckCtl,disptext); return false; }else return true; } else return false; } function DispMessage(CheckCtl,Msg){ if (Msg!=""){ alert(Msg); CheckCtl.select(); CheckCtl.focus(); } } /*功能: 校验一个合法的且在规定范围内的浮点数 入口参数: CheckCtl: 要校验的输入框 Min: 下限 Max: 上限 Msg: 出错显示的信息 */ function CheckFloatRange(CheckCtl,Min, Max,Msg,page){ if (!IsNum(CheckCtl,Msg,page,null,1)) return false; var v=parseFloat(Trim(CheckCtl.value)); if ( (vMax) ){ if (page) showguide(page); DispMessage(CheckCtl,Msg); return false; } return true; } /*判断是否是数字的函数 输入: txtctl 输入的文本控件 message 显示的错误信息 返回值 是数字返回true,不是返回false floatcount: 小数的最高位数(如果没有该参数,则默认为4位) 如果没有page参数,有floatcunt参数则:把page 置null 如: IsNum(txtctl,"出错显示的信息",null,5) */ function IsNum(txtctl,message,page,floatcount,norange){ var s=new String(Trim(txtctl.value)); var result=true; var num=Number(s); if ( (isNaN(num)) || (s=="") ){ result=false; }else if (num>maxfn){ if (!norange){ message=overerrormsg; result=false; } }else{ limitcount=floatcount?floatcount:4; var array=s.split("."); if (array[1]==null) count=-1; else{ var str=new String(array[1]); count=str.length; } if (count>limitcount){ if (page) showguide(page); b=confirm("小数位数超过"+limitcount+"位,是否继续?"); if (b) return true; else{ txtctl.select(); txtctl.focus(); return false; } } } if (!result){ if (page) showguide(page); DispMessage(txtctl,message); return false; } return true; } //取整函数 //eg. Round(132.123456) 为 132.12 //eg. Round(132.123456,4) 为 132.1234 //eg. Round(132.123456,0) 为 132 function Round(i,digit){ if(digit==0) p=1; else{ if(digit) p=Math.pow(10,digit); else p=100; } return Math.round(i*p)/p; } //四舍五入函数,为了兼顾IE5(参数:欲转换数字,小数点后几位)返回NUMBER,liwenjie function NBround(nb,len) { var strnb=new String(nb); if (nb < 0.0000001) return new Number(0); // 小于0.1E-7的按0处理 pos = strnb.indexOf("."); if ((pos == -1) || (strnb.length-pos-1)max)) return false; } if (min) { var min = Cal_strtodate(min); if ((min!=0)&&(date30){ month++; day-=30; } } } thedate.setTime(new Date(year,month-1,day)); return (year<=9999); } /*功能: 把一个日期加上n天(按照精确日期计算) 入口参数: thedate: 要计算的日期对象 days: 增加的天数 如果计算出的日期不合法: 年大于9999等,则返回false,否则true add by aiai*/ function addday1(thedate,days){ day=thedate.getDate(); month=thedate.getMonth()+1; year=thedate.getFullYear(); thedate.setTime(new Date(year,month-1,day+days)); return (thedate.getFullYear()<=9999); } /*功能: 比较两个日期的大小,如果开始日期大于结束日期,返回false; 入口参数: BDate:开始日期 EDate:结束日期 Msg: 出错显示的信息 */ function CheckDiffDate(BDate,EDate,Msg){ return CheckDiffDateNumber(BDate,EDate,0,Msg); } /*功能: 比较两个日期的大小,如果开始日期大于结束日期,返回false; 入口参数: BDate:开始日期 EDate:结束日期 Msg: 出错显示的信息 */ function CheckDiffDateNumber(BDate,EDate,Days,Msg){ if ( (!CheckEmpty(BDate,"请输入日期!")) || (!CheckEmpty(EDate,"请输入日期!")) ) return false; str = BDate.value; aa = str.split("-"); BYear = parseInt(aa[0]); BMonth = parseInt(aa[1]); BDay = parseInt(aa[2]); str = EDate.value; bb = str.split("-"); EYear = parseInt(bb[0]); EMonth = parseInt(bb[1]); EDay = parseInt(bb[2]); if(BYear<1900){ DispMessage(BDate,"日期不能小于1900年!"); return false; } if(EYear<1900){ DispMessage(EDate,"日期不能小于1900年!"); return false; } b=(BYear*10000)+(BMonth*100)+BDay+Days; e=(EYear*10000)+(EMonth*100)+EDay; if(e==b) return true; else if(e>b) return true; else{ DispMessage(BDate,Msg); return false; } } /*功能: 将一个字符串转化为日期对象: Str 字符串 */ function StrToDate(str){ var arrayx=str.split("-"); var datex=new Date(arrayx[0],arrayx[1]-1,arrayx[2]); //var datex=new Date(parseInt(arrayx[0]),parseInt(arrayx[1]-1),parseInt(arrayx[2])); return datex; }