<script> //get the language from cookie Function getLanguage()function getLanguage() { // cookies are separated by semicolons var aCookie = document.cookie.split("; "); for (var i=0; i < aCookie.length; i++) { // a name/value pair (a crumb) is separated by an equal sign var aCrumb = aCookie[i].split("="); if (aCrumb[0] =="TASWEBLANGUAGE") return aCrumb[1]; } // a cookie with the requested name does not exist return"0"; } Function getAllAttributes()function getAllAttributes(object) { var strAttributes=""; for(var i=0;i<object.attributes.length;i++) { strAttributes=strAttributes+object.attributes(i).name+"," } alert(strAttributes); returntrue; } Function hideCalendar()function hideCalendar() { HiddenDiv(); returntrue; } Function isDate()functionisDate(sDate) { var iaMonthDays = [31,28,31,30,31,30,31,31,30,31,30,31]; var iaDate =new Array(3); var year, month, day; if (arguments.length !=1) returnfalse; iaDate = sDate.toString().split("-"); if (iaDate.length !=3) returnfalse; if (iaDate[1].length >2 || iaDate[2].length >2) returnfalse; if(iaDate[0] =="" || iaDate[1] =="" || iaDate[2] =="") returnfalse; if(isNaN(iaDate[0]) || isNaN(iaDate[1]) || isNaN(iaDate[2])) returnfalse; year= parseFloat(iaDate[0]); month= parseFloat(iaDate[1]); day=parseFloat(iaDate[2]); if (year<1900 || year>2100) returnfalse; if (((year % 4==0) && (year % 100 !=0)) || (year % 400==0)) iaMonthDays[1]=29; if (month<1 || month>12) returnfalse; if (day<1 || day> iaMonthDays[month-1]) returnfalse; returntrue; } //如果输入的不是日期型,则修改为当前日期 Function checkDateValue()function checkDateValue(dateCtr) { while(dateCtr.value.toString().indexOf("/") >0) { dateCtr.value = dateCtr.value.toString().replace("/","-"); } if(!isDate(dateCtr.value)) dateCtr.value=getNowDate(); returntrue; } //当前日期 Function getNowDate()function getNowDate() { var nn=newDate(); year1=nn.getYear(); mon1=nn.getMonth()+1; date1=nn.getDate(); var monstr1; var datestr1 if(mon1<10) monstr1="0"+mon1; else monstr1=""+mon1; if(date1<10) datestr1="0"+date1; else datestr1=""+date1; return year1+"-"+monstr1+"-"+datestr1; } //目标日期 Function getlastweekDate()function getlastweekDate() { var nn=newDate(); year1=nn.getYear(); mon1=nn.getMonth()+1; date1=nn.getDate(); var mm=newDate(year1,mon1-1,date1); var tmp1=newDate(2000,1,1); var tmp2=newDate(2000,1,15); var ne=tmp2-tmp1; var mm2=newDate(); mm2.setTime(mm.getTime()-ne); year2=mm2.getYear(); mon2=mm2.getMonth()+1; date2=mm2.getDate(); if(mon2<10) monstr2="0"+mon2; else monstr2=""+mon2; if(date2<10) datestr2="0"+date2; else datestr2=""+date2; return year2+"-"+monstr2+"-"+datestr2; } var gdCtrl =newObject(); var goSelectTag =new Array(); var gcGray ="#808080"; var gcToggle ="#FB8664"; var gcBG ="#e5e6ec"; var gcClose ="#006600"; var wkBgColor="Gray"; var previousObject = null; var gdCurDate =newDate(); var giYear = gdCurDate.getFullYear(); var giMonth = gdCurDate.getMonth()+1; var giDay = gdCurDate.getDate(); Function fSetDate()function fSetDate(iYear, iMonth, iDay) { var VicPopCal= document.getElementById("VicPopCal"); VicPopCal.style.visibility ="hidden"; if ((iYear ==0) && (iMonth ==0) && (iDay ==0)) { gdCtrl.value =""; } else { iMonth = iMonth +100+""; iMonth = iMonth.substring(1); iDay = iDay +100+""; iDay = iDay.substring(1); if(gdCtrl.tagName =="INPUT") { gdCtrl.value = iYear+"-"+iMonth+"-"+iDay; } else { gdCtrl.innerText = iYear+"-"+iMonth+"-"+iDay; } } for (i in goSelectTag) goSelectTag[i].style.visibility ="visible"; goSelectTag.length =0; window.returnValue=gdCtrl.value; hidControl(); // window.close(); } Function fSetClose()function fSetClose() { var VicPopCal= document.getElementById("VicPopCal"); VicPopCal.style.visibility ="hidden"; hidControl(); } Function HiddenDiv()function HiddenDiv() { var i; var VicPopCal= document.getElementById("VicPopCal"); VicPopCal.style.visibility ="hidden"; for (i in goSelectTag) goSelectTag[i].style.visibility ="visible"; goSelectTag.length =0; hidControl(); } Function fSetSelected()function fSetSelected(aCell) { var tbSelMonth = document.getElementById("tbSelMonth"); var tbSelYear = document.getElementById("tbSelYear"); var iOffset =0; var iYear = parseInt(tbSelYear.value); var iMonth = parseInt(tbSelMonth.value); aCell.bgColor = gcBG; with (aCell.children["cellText"]) { var iDay = parseInt(innerText); if (color==gcGray) iOffset = (Victor<10)?-1:1; iMonth += iOffset; if(iMonth<1) { iYear--; iMonth =12; } elseif (iMonth>12) { iYear++; iMonth =1; } } fSetDate(iYear, iMonth, iDay); } Function Point()function Point(iX, iY) { this.x = iX; this.y = iY; } Function fBuildCal()function fBuildCal(iYear, iMonth) { var aMonth=new Array(); for(i=1;i<7;i++) aMonth[i]=new Array(i); var dCalDate=newDate(iYear, iMonth-1, 1); var iDayOfFirst=dCalDate.getDay(); var iDaysInMonth=newDate(iYear, iMonth, 0).getDate(); var iOffsetLast=newDate(iYear, iMonth-1, 0).getDate()-iDayOfFirst+1; var iDate =1; var iNext =1; for (d =0; d <7; d++) aMonth[1][d] = (d<iDayOfFirst)?-(iOffsetLast+d):iDate++; for (w =2; w <7; w++) for (d =0; d <7; d++) aMonth[w][d] = (iDate<=iDaysInMonth)?iDate++:-(iNext++); return aMonth; } Function fDrawCal()function fDrawCal(iYear, iMonth, iCellHeight, sDateTextSize) { switch(getLanguage()) { case"0": var WeekDay=new Array("SU","MO","TU","WE","TH","FR","SA"); break; case"1": var WeekDay=new Array("日","一","二","三","四","五","六"); break; case"2": var WeekDay=new Array("日","一","二","三","四","五","六"); break; } var styleWkTD =" bgcolor='"+wkBgColor+"' bordercolor='"+wkBgColor+"' valign='middle' align='center' height='"+iCellHeight+"' style='font:bold arial "+sDateTextSize+";"; var styleTD =" bgcolor='"+gcBG+"' bordercolor='"+gcBG+"' valign='middle' align='center' height='"+iCellHeight+"' style='font:bold arial "+sDateTextSize+";"; with (document) { write("<tr>"); for(i=0; i<7; i++) { write("<td "+styleWkTD+"color:white' >"+WeekDay[i] +"</td>"); } write("</tr>"); for (w =1; w <7; w++) { write("<tr>"); for (d =0; d <7; d++) { write("<td id=calCell "+styleTD+"cursor:hand;' onMouseOver='this.bgColor=gcToggle' onMouseOut='this.bgColor=gcBG' οnclick='fSetSelected(this)'>"); write("<font id=cellText Victor='Hcy_Flag'> </font>"); write("</td>") } write("</tr>"); } } } Function fUpdateCal()function fUpdateCal() { var iYear=document.getElementById("tbSelYear").value; var iMonth=document.getElementById("tbSelMonth").value; myMonth = fBuildCal(iYear, iMonth); var i =0; for (w =0; w <6; w++) for (d =0; d <7; d++) with (cellText[(7*w)+d]) { Victor = i++; if (myMonth[w+1][d]<0) { color = gcGray; innerText =-myMonth[w+1][d]; } else { color = ((d==0)||(d==6))?"red":"black"; innerText = myMonth[w+1][d]; } } } Function fSetYearMon()function fSetYearMon(iYear, iMon) { var tbSelMonth = document.getElementById("tbSelMonth"); var tbSelYear = document.getElementById("tbSelYear"); tbSelMonth.options[iMon-1].selected =true; for (i =0; i < tbSelYear.length; i++) if (tbSelYear.options[i].value == iYear) tbSelYear.options[i].selected =true; fUpdateCal(iYear, iMon); } Function fPrevMonth()function fPrevMonth() { var tbSelMonth = document.getElementById("tbSelMonth"); var tbSelYear = document.getElementById("tbSelYear"); var iMon = tbSelMonth.value; var iYear = tbSelYear.value; if (--iMon<1) { iMon =12; iYear--; } fSetYearMon(iYear, iMon); } Function fNextMonth()function fNextMonth() { var tbSelMonth = document.getElementById("tbSelMonth"); var tbSelYear = document.getElementById("tbSelYear"); var iMon = tbSelMonth.value; var iYear = tbSelYear.value; if (++iMon>12) { iMon =1; iYear++; } fSetYearMon(iYear, iMon); } Function fToggleTags()function fToggleTags() { with (document.all.tags("SELECT")) { for (i=0; i<length; i++) { if (document.all.tags("SELECT").item(i).Victor==null) return; if ((item(i).Victor!="Won")&&fTagInBound(item(i))) { item(i).style.visibility ="hidden"; goSelectTag[goSelectTag.length] = item(i); } } } } Function fTagInBound()function fTagInBound(aTag) { var VicPopCal= document.getElementById("VicPopCal"); with (VicPopCal.style) { var l = parseInt(left); var t = parseInt(top); var r = l+parseInt(width); var b = t+parseInt(height); var ptLT = fGetXY(aTag); return !((ptLT.x>r)||(ptLT.x+aTag.offsetWidth<l)||(ptLT.y>b)||(ptLT.y+aTag.offsetHeight<t)); } } Function getAbsolutePos()function getAbsolutePos(el) { var r = { x: el.offsetLeft, y: el.offsetTop }; if (el.offsetParent) { var tmp = getAbsolutePos(el.offsetParent); r.x += tmp.x; r.y += tmp.y; } return r; } Function hidControl()function hidControl() { var tags =new Array("applet", "iframe", "select"); var el= document.getElementById("VicPopCal"); var p = getAbsolutePos(el); var EX1 = p.x; var EX2 = el.offsetWidth + EX1; var EY1 = p.y; var EY2 = el.offsetHeight + EY1; for (var k = tags.length; k >0; ) { var ar = document.getElementsByTagName(tags[--k]); var cc = null; for (var i = ar.length; i >0;) { cc = ar[--i]; p = getAbsolutePos(cc); var CX1 = p.x; var CX2 = cc.offsetWidth + CX1; var CY1 = p.y; var CY2 = cc.offsetHeight + CY1; if (el.style.visibility =='hidden' || (CX1 > EX2) || (CX2 < EX1) || (CY1 > EY2) || (CY2 < EY1)) { if(cc.getAttribute("ID") !="tbSelYear"&& cc.getAttribute("ID") !="tbSelMonth") cc.style.visibility ="visible"; } else { if(cc.getAttribute("ID") !="tbSelYear"&& cc.getAttribute("ID") !="tbSelMonth") cc.style.visibility ="hidden"; } } } } // Main: popCtrl is the widget beyond which you want this calendar to appear; // dateCtrl is the widget into which you want to put the selected date. // i.e.: <input type="text" name="dc" style="text-align:center"readonly><INPUT type="button" value="V" onclick="fPopCalendar(dc,dc);return false"> Function fPopCalendar()function fPopCalendar(popCtrl, dateCtrl,strDate) { var ppCtl = popCtrl;//document.getElementById(popCtrl); var dateCtl = dateCtrl;//document.getElementById(dateCtrl); var VicPopCal= document.getElementById("VicPopCal"); // getAllAttributes(VicPopCal); if (ppCtl == previousObject) { if (VicPopCal.style.visibility =="visible") { HiddenDiv(); returntrue; } } previousObject = ppCtl; gdCtrl = dateCtl; if( strDate == null || strDate.length !=10 ) { strDate = dateCtl.value; } fInitialDate(strDate); fSetYearMon(giYear, giMonth); // var point1 = fGetXY(ppCtl); var point1 = fGetXY(dateCtrl); with (VicPopCal.style) { left= point1.x; //left= point1.x - parseFloat(dateCtrl.style.width.replace("px","")) -6; // top = point1.y+popCtrl.offsetHeight; top = point1.y+dateCtrl.offsetHeight; width = VicPopCal.offsetWidth-10; height = VicPopCal.offsetHeight-60; fToggleTags(point1); visibility ='visible'; } hidControl(); } Function fGetXY()function fGetXY(aTag) { var oTmp = aTag; var pt =new Point(0,0); do { pt.x += oTmp.offsetLeft; pt.y += oTmp.offsetTop; oTmp = oTmp.offsetParent; } while(oTmp.tagName!="BODY"); return pt; } // Added by Han Chen Function fInitialDate()function fInitialDate(strDate) { if( strDate == null || strDate.length !=10 ) returnfalse; var sYear = strDate.substring(0,4); var sMonth = strDate.substring(5,7); var sDay = strDate.substring(8,10); if( sMonth.charAt(0) =='0' ) { sMonth = sMonth.substring(1,2); } if( sDay.charAt(0) =='0' ) { sDay = sDay.substring(1,2); } var nYear = parseInt(sYear ); var nMonth = parseInt(sMonth); var nDay = parseInt(sDay ); if ( isNaN(nYear ) ) returnfalse; if ( isNaN(nMonth) ) returnfalse; if ( isNaN(nDay ) ) returnfalse; var arrMon =new Array(12); arrMon[ 0] =31; arrMon[ 1] = nYear % 4==0 ? 29:28; arrMon[ 2] =31; arrMon[ 3] =30; arrMon[ 4] =31; arrMon[ 5] =30; arrMon[ 6] =31; arrMon[ 7] =31; arrMon[ 8] =30; arrMon[ 9] =31; arrMon[10] =30; arrMon[11] =31; if ( nYear <1900 || nYear >2100 ) returnfalse; if ( nMonth <1 || nMonth >12 ) returnfalse; if ( nDay <1 || nDay > arrMon[nMonth -1] ) returnfalse; giYear = nYear; giMonth = nMonth; giDay = nDay; returntrue; } switch(getLanguage()) { case"0": var gMonths =new Array("Jan","Feb","Mar.","Apr.","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); break; case"1": // var gMonths =new Array("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"); var gMonths =new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"); break; case"2": // var gMonths =new Array("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"); var gMonths =new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"); break; } with (document) { write("<Div id='VicPopCal' style='POSITION:absolute;VISIBILITY:hidden;border:1px ridge;z-index:100;'>"); write("<table border='0' cellSpacing='0' cellPadding='1' bgcolor='#cccccc'>"); write("<TR>"); write("<td valign='middle' align='center'><input type='button' name='PrevMonth' value='<' style='height:20;width:20;FONT:bold' onClick='fPrevMonth()'>"); write(" <SELECT id='tbSelYear' name='tbSelYear' οnchange='fUpdateCal()' Victor='Won'>"); for(i=1980;i<=2020;i++) switch(getLanguage()) { case"0": write("<OPTION value='"+i+"'>"+i+" </OPTION>"); break; case"1": write("<OPTION value='"+i+"'>"+i+" 年</OPTION>"); break; case"2": write("<OPTION value='"+i+"'>"+i+" 年</OPTION>"); break; } write("</SELECT>"); write(" <select id='tbSelMonth' name='tbSelMonth' οnchange='fUpdateCal()' Victor='Won'>"); for (i=0; i<12; i++) write("<option value='"+(i+1)+"'>"+gMonths[i]+"</option>"); write("</SELECT>"); write(" <input type='button' name='PrevMonth' value='>' style='height:20;width:20;FONT:bold' οnclick='fNextMonth()'>"); write("</td>"); write("</TR><TR>"); write("<td align='center'>"); write("<DIV style='background-color:teal'><table width='100%' border='0'>"); fDrawCal(giYear, giMonth, 17, '12'); write("</table></DIV>"); write("</td>"); write("</TR><TR><TD align='center'>"); //write("<TABLE width='100%'><TR><TD align='center'>"); write("<TABLE width='100%' border='0' cellSpacing='0' cellPadding='0'><TR><TD colspan='2' align='center'>"); switch(getLanguage()) { case"0": //write("<B style='cursor:hand;color:"+gcClose+"' οnclick='fSetDate(0,0,0)' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>Clear</B>"); //write("</td><td algin='center'>"); write("<B style='cursor:hand;color:"+gcClose+"' οnclick='fSetDate(giYear,giMonth,giDay)' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>Today<BR/>"+giYear+"-"+giMonth+"-"+giDay+"</B>"); write("</td><td algin='center'>"); write("<B style='cursor:hand;color:"+gcClose+"' οnclick='fSetClose()' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>Close</B>"); break; case"1": //write("<B style='cursor:hand;color:"+gcClose+"' οnclick='fSetDate(0,0,0)' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>清空</B>"); //write("</td><td algin='center'>"); write("<B style='cursor:hand;color:"+gcClose+"' οnclick='fSetDate(giYear,giMonth,giDay)' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>今天<BR/>"+giYear+"-"+giMonth+"-"+giDay+"</B>"); write("</td><td algin='center'>"); write("<B style='cursor:hand;color:"+gcClose+"' οnclick='fSetClose()' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>关闭</B>"); break; case"2": //write("<B style='cursor:hand;color:"+gcClose+"' οnclick='fSetDate(0,0,0)' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>清空</B>"); //write("</td><td algin='center'>"); write("<B style='cursor:hand;color:"+gcClose+"' οnclick='fSetDate(giYear,giMonth,giDay)' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>今天<BR/>"+giYear+"-"+giMonth+"-"+giDay+"</B>"); write("</td><td algin='center'>"); write("<B style='cursor:hand;color:"+gcClose+"' οnclick='fSetClose()' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=gcClose'>關閉</B>"); break; } write("</td></tr></table>"); write("</TD></TR>"); write("</TABLE></Div>"); } </script> <table border="0" cellpadding="0" cellspacing="0" style="height: 21px"> <tr valign="top"> <td><asp:TextBox ID="txtDateTime" runat="server" Width="86px" Height="100%" BackColor="White"></asp:TextBox></td> <td><asp:Button ID="imgSelect" runat="server" style="width: 20px; height: 98%" Text=""/></td> </tr> </table>
'in then code
Partial Class SelectDateTimeClass SelectDateTime Inherits System.Web.UI.UserControl PublicProperty DateTime()Property DateTime() AsString Get ReturnMe.txtDateTime.Text.Trim EndGet Set(ByVal value AsString) Me.txtDateTime.Text = value DisplayProperty() EndSet End Property PublicProperty DateTextWith()Property DateTextWith() AsString Get ReturnMe.txtDateTime.Width.ToString EndGet Set(ByVal value AsString) DimStrAsString IfRight(value, 1) ="x"Then Str=Left(value, Len(value) -2) Me.txtDateTime.Width = Unit.Pixel(Str) ElseIfRight(value, 1) ="%"Then Str=Left(value, Len(value) -1) Me.txtDateTime.Width = Unit.Percentage(Str) Else Me.txtDateTime.Width = value EndIf EndSet End Property PublicProperty DateEnabled()Property DateEnabled() AsString Get ReturnMe.txtDateTime.Text.Trim EndGet Set(ByVal value AsString) Me.txtDateTime.Enabled = value Me.imgSelect.Enabled = value EndSet End Property ProtectedSub DisplayPrEnabled()Sub DisplayPrEnabled() ViewState("DateTextWith") =Me.txtDateTime.Enabled End Sub ProtectedSub DisplayProWith()Sub DisplayProWith() ViewState("DateTextWith") =Me.txtDateTime.Width End Sub ProtectedSub DisplayProperty()Sub DisplayProperty() ViewState("DateTime") =Me.txtDateTime.Text End Sub ProtectedSub Page_Load()Sub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load IfMe.Page.IsPostBack =FalseThen Dim script AsString="fPopCalendar("+Me.imgSelect.ClientID +","+Me.txtDateTime.ClientID +");return false" Me.imgSelect.Attributes.Add("onclick", script) Me.txtDateTime.Attributes.Add("onfocusout", "checkDateValue("&Me.txtDateTime.ClientID &")") EndIf End Sub End Class
'in then script<script>//getthelanguagefromcookieFunctiongetLanguage()functiongetLanguage(){//cookiesareseparatedbysemicolonsvaraCookie=document....