|
//校验身份证
function checkIDCard(KongJianM)
{
var ControlObj=document.getElementById(KongJianM);
if(ControlObj==null)
{
alert("校验错误,控件不存在!");
return false;
}
var idNum = ControlObj.value;
if(idNum=="")
{
return true;
}
var errors=new Array(
"验证通过",
"身份证号码位数不对",
"身份证含有非法字符",
"身份证号码校验错误",
"身份证地区非法",
"身份证出生日期不对");
//身份号码位数及格式检验
var re;
var len = idNum.length;
//身份证位数检验
if(len != 15 && len != 18)
{
alert(errors[1]);
ControlObj.focus();
return false;
}
else if(len == 15)
{
re = new RegExp(/^(\d{6})()?(\d{2})(\d{2})(\d{2})(\d{3})$/);
}
else
{
re = new RegExp(/^(\d{6})()?(\d{4})(\d{2})(\d{2})(\d{3})([0-9xX])$/);
}
var area={11:"北京",12:"天津",13:"河北",14:"山西",
15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",
32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",
37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",
45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",
53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",
64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",
91:"国外"}
var idcard_array = new Array();
idcard_array = idNum.split("");
//地区检验
if(area[parseInt(idNum.substr(0,2))]==null)
{
alert(errors[4]);
ControlObj.focus();
return false;
}
//出生日期正确性检验
var a = idNum.match(re);
if (a != null)
{
if (len==15)
{
var DD = new Date("19"+a[3]+"/"+a[4]+"/"+a[5]);
var flag = DD.getYear()==a[3]&&(DD.getMonth()+1)==a[4]&&DD.getdate()==a[5];
}
else if(len == 18)
{
var DD = new Date(a[3]+"/"+a[4]+"/"+a[5]);
var flag = DD.getFullYear()==a[3]&&(DD.getMonth()+1)==a[4]&&DD.getdate()==a[5];
}
if (!flag)
{
alert(errors[5]);
ControlObj.focus();
return false;
}
//检验校验位
if(len == 18)
{
S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7
+ (parseInt(idcard_array[1]) + parseInt(idcard_array[11])) * 9
+ (parseInt(idcard_array[2]) + parseInt(idcard_array[12])) * 10
+ (parseInt(idcard_array[3]) + parseInt(idcard_array[13])) * 5
+ (parseInt(idcard_array[4]) + parseInt(idcard_array[14])) * 8
+ (parseInt(idcard_array[5]) + parseInt(idcard_array[15])) * 4
+ (parseInt(idcard_array[6]) + parseInt(idcard_array[16])) * 2
+ parseInt(idcard_array[7]) * 1
+ parseInt(idcard_array[8]) * 6
+ parseInt(idcard_array[9]) * 3 ;
Y = S % 11;
M = "F";
JYM = "10X98765432";
M = JYM.substr(Y,1);//判断校验位
//检测ID的校验位
if(M == idcard_array[17])
{
return true;
}
else
{
alert(errors[3]);
ControlObj.focus();
return false;
}
}
}
else
{
alert(errors[2]);
ControlObj.focus();
return false;
}
return true;
}
//k为多条最大行号,可以存在一个隐藏的input控件中
//idArray数组记忆已删除的行号
var idArray = new Array();
function DelRow(env)
{
rowid=env.id;
var Rowindex=0;;
if(idArray.length==0)
{
Rowindex=rowid;
}
else
{
//判断循环是否中断
var shifouzd=0;
for(var i=0;i<idArray.length;i++)
{
if(parseInt(idArray[i])<parseInt(rowid))
{
shifouzd+=1;
}
}
if( shifouzd==0)
{
Rowindex=rowid-idArray.length;
}
else
{
Rowindex=rowid-shifouzd;
}
}
document.getElementById("CloneNodeShow").deleteRow(Rowindex);
idArray.push(rowid);
}
//隐显控制示例
function YinXianKZ(DivID)
{
if(document.getElementById(DivID).style.display=="none")
{
document.getElementById(DivID).style.display="block";
}
else
{
document.getElementById(DivID).style.display="none"
}
}
//即时时钟
function ShowTime()
{
document.getElementById("ALARM").innerText = (new Date()).toLocaleDateString()+ " " + (new Date()).toLocaleTimeString()
TimerID = setTimeout("ShowTime()",1000);
}
//校验金额上限的输入类型
function JinESX()
{
var JinESX=document.getElementById("ShuBenJESX").value;
if(JinESX!="")
{
if(!IsInt(JinESX))
{
alert("金额上限只能是数字");
document.getElementById("ShuBenJESX").focus();
}
}
}
//校验是否是整数
function IsInt(s)
{
var pattern = /^-?\d+$/;
if(s.search(pattern)!=0)
{
return false;
}
return true;
}
//校验是否是数字
function IsNum(s)
{
var pattern = /^\d+(\.\d+)?$/;
if(pattern.test(s))
{
return true;
}
return false;
}
//上传图片
function switchImageUpload(bieMing)
{
var fileUploadControl = document.getElementById(bieMing+"_UpLoad1_Main");
var type = fileUploadControl.getAttribute("type");
if(type == "hidden")
{
fileUploadControl.style.display="";
fileUploadControl.setAttribute("type","normal");
}
else
{
fileUploadControl.style.display="none";
fileUploadControl.setAttribute("type","hidden");
}
}
function NextWeek()
{
try
{
var s;
var d;
s = m_GetControl("ShuRuSJ").value;
d = m_StringToDate(s);
if(d.getDay()!=0)
{
z = m_weekOfYear(d)+1;
//m_GetControl("zhou").value = z;
n = d.getYear();
for(var i=1;i<=7;i++)
{
a = m_dateFromWeek(n,z,i);
yue = parseInt(a.getMonth()+1);
if(yue<10) yue = "0"+yue.toString();
ri = a.getDate();
if(ri<10) ri = "0"+ri.toString();
var date = a.getYear()+"-"+yue+"-"+ri;
m_GetControl(i+"RiQi").value = date;
}
}
else
{
z = m_weekOfYear(d);
//m_GetControl("zhou").value = z;
n = d.getYear();
for(var i=1;i<=7;i++)
{
a = m_dateFromWeek(n,z,i);
yue = parseInt(a.getMonth()+1);
if(yue<10) yue = "0"+yue.toString();
ri = a.getDate();
if(ri<10) ri = "0"+ri.toString();
var date = a.getYear()+"-"+yue+"-"+ri;
m_GetControl(i+"RiQi").value = date;
}
}
}
catch(e)
{
alert("exception");
}
}
//字符串转日期型
function m_StringToDate(str)
{
try
{
var arys= new Array();
arys=str.split(' ')[0].split('-');
var newDate=new Date(arys[0],arys[1]-1,arys[2]);
//alert(newDate.toLocaleDateString());
return newDate;
}
catch (E)
{
return null;
}
}
// 计算日期为当年的第几周
function m_weekOfYear(date)
{
var year = date.getYear();
var month = date.getMonth()+1;
var day = date.getDate();
// 每周从周日开始
var date1 = new Date(year, 0, 1);
var date2 = new Date(year, month-1, day,1);
//alert(date2.toLocaleDateString());
var dayMS = 24*60*60*1000;
var firstDay = (7-date1.getDay())*dayMS;
var weekMS = 7*dayMS;
date1 = date1.getTime();
date2 = date2.getTime();
return Math.ceil((date2-date1-firstDay)/weekMS)+1;
}
//
// 通过周数和星期计算日期
function m_dateFromWeek(year, week, day)
{
// year 年
// week 周
// day 星期 (0-6, 0代表周日)
var date1 = new Date(year, 0, 1);
var dayMS = 24*60*60*1000;
var firstDay = (7-date1.getDay())*dayMS;
var weekMS = (week-2)*7*dayMS;
var result = date1.getTime()+firstDay+weekMS+day*dayMS;
date1.setTime(result);
return date1;//.toLocaleDateString();
}
var k=1;
function AddRow()
{
var i=k;
var tableObject=new Object();
var isneed=true;
tableObject=document.getElementById"CloneNodeShow";
if(isneed)
{
//添加一行
var newTR=tableObject.insertRow();
var td1=newTR.insertCell();
var td2=newTR.insertCell();
var td3=newTR.insertCell();
var td4=newTR.insertCell();
td1.innerHTML='<input type="text" id="username"'+(i+1)+'/>';
//true表示深度克隆
var newSelect1=document.getElementById("KaiShiSJ1").cloneNode(true);
newSelect1.id="KaiShiSJ"+(i+1);
for(var loop=k;loop>0;loop--)
{
if(document.getElementById("JieZhiSJ"+loop)!=null)
{
newSelect1.value=document.getElementById("JieZhiSJ"+loop).value;
break;
}
}
td2.appendChild(newSelect1);
td3.innerHTML='<input type="text" id="JieZhiSJ'+(i+1)+'"/>';
var newSelect2=document.getElementById("1").cloneNode(true);
newSelect2.id=i+1;
td4.appendChild(newSelect2);
}
k=i+1;
}
//比较时间大小
function TimeCompar()
{
var ShenQingRQ=document.getElementById"ShenQingRQ".value;
var ShenPiRQ=document.getElementById("ShenPiRQ").value;
if(ShenQingRQ=="")
{
alert("申请日期不能为空");
return false;
}
ShenQingRQ=ShenQingRQ.replace(/-/g,"/");
ShenPiRQ=ShenPiRQ.replace(/-/g,"/");
if(new Date(ShenQingRQ) >= new Date(ShenPiRQ))
{
return false;
}
return true;
}
//校验多条录入的开始时间不能重
function checktimerepeat()
{
if(k>1)
{
for(var No=1;No<k-1;No++)
{
//判断该行是否已被删除
if("document.getElementById("KaiShiSJ"+(No+1))!=null")
{
var KaiShiSJ1=document.getElementById("KaiShiSJ"+(No+1)).value;
for(var Noloop=(No+1);Noloop<k;Noloop++)
{
//判断该行是否已被删除
if(document.getElementById("KaiShiSJ"+(Noloop+1))!=null)
{
var KaiShiSJ2=document.getElementById("KaiShiSJ"+(Noloop+1)).value;
if(KaiShiSJ1==KaiShiSJ2)
{
return false;
}
}
}
}
}
}
return true;
}
function m_FormSubmitNow()
{
var XingMing=document.getElementById("XingMing").value;
var XingBie=document.getElementById("XingBie").value;
var ChuShengRQ=document.getElementById("ChuShengRQ").value;
var ShengFenZH=document.getElementById("ShengFenZH").value;
var ShenPiRQ=document.getElementById("ShenPiRQ").value;
var ShuBenJESX=document.getElementById("ShuBenJESX").value;
if(XM=="")
{
alert("姓名不能为空");
return false;
}
if(XingBie=="")
{
alert("性别不能为空");
return false;
}
if(ChuShengRQ=="")
{
alert("出生日期不能为空");
return false;
}
if(ShengFenZH=="")
{
alert("身份证号不能为空");
return false;
}
if(!checktimerepeat())
{
alert("开始时间不能重复");
return false;
}
if(TimeCompar())
{
alert("审批日期必须大于申请日期");
return false;
}
if(ShenPiRQ=="")
{
alert("审批日期不能为空");
return false;
}
if(ShuBenJESX=="")
{
alert("金额上限不能为空");
return false;
}
if(parseFloat(document.getElementById("ShuBenJE").value)>parseFloat(document.getElementById("ShuBenJESX").value))
{
alert("书费金额不能大于金额上限");
return false;
}
alert("校验完成");
}
function SoSuo_Tab()
{
var ShiFouSousuo1="1";
if(ShiFouSousuo1=="1")
{
document.getElementById("tab1").style.display="block";
document.getElementById("tab2").style.display="block";
document.getElementById("tab3").style.display="none";
}
}
function TreeTSHBG(control)
{
var shu=control.id.substring(5,8);
var i=parseInt(shu)+1;
var m=parseInt(shu)-1;
switch(parseInt(shu))
{
case 0:
document.getElementById("tab1").style.display="block";
document.getElementById("tab2").style.display="none";
document.getElementById("tab3").style.display="none";
break;
case 1:
document.getElementById("tab1").style.display="none";
document.getElementById("tab2").style.display="block";
document.getElementById("tab3").style.display="none";
break;
case 2:
document.getElementById("tab1").style.display="none";
document.getElementById("tab2").style.display="block";
document.getElementById("tab3").style.display="none";
break;
default:
break;
}
}
function M_GetControl(KongJianID)
{
var KongJian=document.getElementById(KongJianName);
return KongJian;
}
function JiSuanJE(env)
{
var ZongShuL=0;
var ZongJinE=0;
var KongJianID=Envi.id;
var HangHao=KongJianID.substring(8);
var KongJianLX=KongJianID.substring(0,8);
for(var loop=0;loop<5;loop++)
{
var ShuBenSL=document.getElementById("ShuBenSL"+loop).value;
var ShuBenDJ=document.getElementById("ShuBenDJ"+loop).value;
var XiaoJi=0;
//计算书本数量和价钱
if(parseInt(HangHao)==parseInt(loop))
{
if(ShuBenSL!="")
{
if(KongJianLX=="ShuBenSL")
{
if(!IsInt(ShuBenSL))
{
alert("请输入正确的书本数量!");
document.getElementById(KongJianID).focus();
return false;
}
}
}
//校验书本单价是否是浮点型
if(ShuBenDJ!="")
{
if(KongJianLX=="ShuBenDJ")
{
if(!IsNum(ShuBenDJ))
{
alert("请输入正确的书本单价!");
document.getElementById(KongJianID).focus();
return false;
}
}
}
if(ShuBenSL!=""&&ShuBenDJ!="")
{
//校验书本数量是否整型
XiaoJi=parseFloat(ShuBenSL)*parseFloat(ShuBenDJ);
document.getElementById("XiaoJi"+loop).value=XiaoJi;
}
}
else
{
XiaoJi=document.getElementById("XiaoJi"+loop).value;
}
if(ShuBenSL!="")
{
ZongShuL=parseInt(ShuBenSL)+parseInt(ZongShuL);
}
if(XiaoJi!="")
{
ZongJinE=parseFloat(ZongJinE)+parseFloat(XiaoJi);
}
}
document.getElementById("ShuBenSL").value=ZongShuL;
document.getElementById("ShuBenJE").value=ZongJinE;
}
/*计算下周日期*/
function getDay()
{
var D,today="";
d = new Date();
today+= d.getYear()+ "-";
var yue = d.getMonth()+1;
if(yue<10)
yue = "0"+yue;
today+= yue +"-";
today+= d.getDate();
m_GetControl("ShuRuSJ").value =today;
}
//校验邮箱地址
function CheckMailFormat(KongJianM)
{
var ControlObj=document.getElementById(kongjianm);
//如果为空,退出
if (ControlObj==null)
{
alert("校验错误,控件不存在!");
}
if(ControlObj.value=="")
{
return false;
}
var filter=/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
if(!filter.test(ControlObj.value))
{
alert("输入的email地址请保证正确的格式!");
ControlObj.value="";
ControlObj.focus();
}
} |
|