//即时时钟
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 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();
}
}作者: sunnygirl 时间: 2009-11-22 07:05
有时候,不是对方不在乎你,而是你把对方看的太重。