⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ptymdate.cs

📁 c# vs2005(asp.net2.0) 下的一个日期控件,来自网上的脚本,对其作了更改,修改了些错误,目前已经在项目中使用,感觉不错
💻 CS
📖 第 1 页 / 共 2 页
字号:
		var m = (strMonth) ? strMonth : new Date().getMonth() + 1;
		var s = ""&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select Author=meizz name=tmpSelectMonth style='font-size: 12px' ""
			s += ""onblur='document.all.tmpSelectMonthLayer.style.display=\""none\""' ""
			s += ""onchange='document.all.tmpSelectMonthLayer.style.display=\""none\"";""
			s += ""parent.meizzTheMonth = this.value; parent.meizzSetDay(parent.meizzTheYear,parent.meizzTheMonth)'>\r\n"";
		var selectInnerHTML = s;
		for (var i = 1; i < 13; i++)
		{
			if (i == m)
			{selectInnerHTML += ""<option Author=wayx value='""+i+""' selected>""+i+""月""+""</option>\r\n"";}
			else {selectInnerHTML += ""<option Author=wayx value='""+i+""'>""+i+""月""+""</option>\r\n"";}
		}
		selectInnerHTML += ""</select>"";
		odatelayer.tmpSelectMonthLayer.style.display="""";
		odatelayer.tmpSelectMonthLayer.innerHTML = selectInnerHTML;
		odatelayer.tmpSelectMonth.focus();
		}

		function closeLayer()             
		{
			document.all.meizzDateLayer.style.display=""none"";
		}

		function IsPinYear(year)         
		{
			if (0==year%4&&((year%100!=0)||(year%400==0))) return true;else return false;
		}

		function GetMonthCount(year,month)
		{
			var c=MonHead[month-1];if((month==2)&&IsPinYear(year)) c++;return c;
		}
		function GetDOW(day,month,year)  
		{
			var dt=new Date(year,month-1,day).getDay()/7; return dt;
		}

		function meizzPrevY() 
		{
			if(meizzTheYear > 999 && meizzTheYear <10000){meizzTheYear--;}
			else{alert(""年份超出范围(1000-9999)!"");}
			meizzSetDay(meizzTheYear,meizzTheMonth);
		}
		function meizzNextY() 
		{
			if(meizzTheYear > 999 && meizzTheYear <10000){meizzTheYear++;}
			else{alert(""年份超出范围(1000-9999)!"");}
			meizzSetDay(meizzTheYear,meizzTheMonth);
		}
		function meizzToday() 
		{
			var today;
			meizzTheYear = new Date().getFullYear();
			meizzTheMonth = new Date().getMonth()+1;
			today=new Date().getDate();
			//meizzSetDay(meizzTheYear,meizzTheMonth);
			if(outObject){
				outObject.value=meizzTheYear + ""-"" + meizzTheMonth + ""-"" + today;
			}
			closeLayer();
		}
		function meizzPrevM() 
		{
			if(meizzTheMonth>1){meizzTheMonth--}else{meizzTheYear--;meizzTheMonth=12;}
			meizzSetDay(meizzTheYear,meizzTheMonth);
		}
		function meizzNextM()  
		{
			if(meizzTheMonth==12){meizzTheYear++;meizzTheMonth=1}else{meizzTheMonth++}
			meizzSetDay(meizzTheYear,meizzTheMonth);
		}

		function meizzSetDay(yy,mm) 
		{
		meizzWriteHead(yy,mm);
		meizzTheYear=yy;
		meizzTheMonth=mm;
		  
		for (var i = 0; i < 39; i++){meizzWDay[i]=""""};  
		var day1 = 1,day2=1,firstday = new Date(yy,mm-1,1).getDay();  
		for (i=0;i<firstday;i++)meizzWDay[i]=GetMonthCount(mm==1?yy-1:yy,mm==1?12:mm-1)-firstday+i+1	
		for (i = firstday; day1 < GetMonthCount(yy,mm)+1; i++){meizzWDay[i]=day1;day1++;}
		for (i=firstday+GetMonthCount(yy,mm);i<39;i++){meizzWDay[i]=day2;day2++}
		for (i = 0; i < 39; i++)
		{ var da = eval(""odatelayer.meizzDay""+i)    
			if (meizzWDay[i]!="""")
			{ 
				da.borderColorLight=""#76A0CF"";
				da.borderColorDark=""#76A0CF"";
				if(i<firstday)		
				{
					da.innerHTML=""<font style=' color: #B5C5D2;'>"" + meizzWDay[i] + ""</font>"";
					da.title=(mm==1?12:mm-1) +""月"" + meizzWDay[i] + ""日"";
					da.onclick=Function(""meizzDayClick(this.innerText,-1)"");
					
					if(!outDate)
						da.style.backgroundColor = ((mm==1?yy-1:yy) == new Date().getFullYear() && 
							(mm==1?12:mm-1) == new Date().getMonth()+1 && meizzWDay[i] == new Date().getDate()) ?
							""#E4E3F2"":""#FFFFFF"";
					else
					{
						da.style.backgroundColor =((mm==1?yy-1:yy)==outDate.getFullYear() && (mm==1?12:mm-1)== outDate.getMonth() + 1 && 
						meizzWDay[i]==outDate.getDate())? ""#E8F5E7"" :
						(((mm==1?yy-1:yy) == new Date().getFullYear() && (mm==1?12:mm-1) == new Date().getMonth()+1 && 
						meizzWDay[i] == new Date().getDate()) ? ""#E4E3F2"":""#FFFFFF""); 
						if((mm==1?yy-1:yy)==outDate.getFullYear() && (mm==1?12:mm-1)== outDate.getMonth() + 1 && 
						meizzWDay[i]==outDate.getDate())
						{
							//da.borderColorLight=""#E4E3F2"";
							//da.borderColorDark=""#E4E3F2"";  
						}
					}
					
				}
				else if (i>=firstday+GetMonthCount(yy,mm))		
				{
					da.innerHTML=""<font style=' color: #B5C5D2;'>"" + meizzWDay[i] + ""</font>"";
					da.title=(mm==12?1:mm+1) +""月"" + meizzWDay[i] + ""日"";
					da.onclick=Function(""meizzDayClick(this.innerText,1)"");
					if(!outDate)
						da.style.backgroundColor = ((mm==12?yy+1:yy) == new Date().getFullYear() && 
							(mm==12?1:mm+1) == new Date().getMonth()+1 && meizzWDay[i] == new Date().getDate()) ?
							""#E4E3F2"":""#FFFFFF"";
					else
					{
						da.style.backgroundColor =((mm==12?yy+1:yy)==outDate.getFullYear() && (mm==12?1:mm+1)== outDate.getMonth() + 1 && 
						meizzWDay[i]==outDate.getDate())? ""#E8F5E7"" : 
						(((mm==12?yy+1:yy) == new Date().getFullYear() && (mm==12?1:mm+1) == new Date().getMonth()+1 && 
						meizzWDay[i] == new Date().getDate()) ? ""#E4E3F2"":""#FFFFFF""); 
						if((mm==12?yy+1:yy)==outDate.getFullYear() && (mm==12?1:mm+1)== outDate.getMonth() + 1 && 
						meizzWDay[i]==outDate.getDate())
						{
							da.borderColorLight=""#E4E3F2"";
							da.borderColorDark=""#E4E3F2"";  
						}
					}
				}
				else		
				{
					da.innerHTML=""<font style=' color: #3E5468;'>"" + meizzWDay[i] + ""</FONT>"";
					da.title=mm +""月"" + meizzWDay[i] + ""日"";
					da.onclick=Function(""meizzDayClick(this.innerText,0)"");	
					if(!outDate)
						da.style.backgroundColor = (yy == new Date().getFullYear() && mm == new Date().getMonth()+1 && meizzWDay[i] == new Date().getDate())?
							""#FFFFFF"":""#FFFFFF"";
					else
					{
						da.style.backgroundColor =(yy==outDate.getFullYear() && mm== outDate.getMonth() + 1 && meizzWDay[i]==outDate.getDate())?
							""#D5ECD2"":((yy == new Date().getFullYear() && mm == new Date().getMonth()+1 && meizzWDay[i] == new Date().getDate())?
							""#E4E3F2"":""#F8F8FC""); 
						if(yy==outDate.getFullYear() && mm== outDate.getMonth() + 1 && meizzWDay[i]==outDate.getDate())
						{
							//da.borderColorLight=""#E4E3F2"";
							//da.borderColorDark=""#E4E3F2""; 
						}
					}
				}
				da.style.cursor=""hand""
				da.onmouseover=Function(""this.backgroundColor='#000000';this.borderColorDark='#000099';this.borderColorLight='#000099';"");
				da.onmouseout=Function(""this.bgColor='#000000';this.borderColorDark='#9CBADE';this.borderColorLight='#9CBADE';"");
			}
			else{da.innerHTML="""";da.style.backgroundColor="""";da.style.cursor=""default"";da.onmouseover=Function(""this.backgroundColor='#000000';this.borderColorDark='#000099';this.borderColorLight='#000099';"");
				da.onmouseout=Function(""this.bgColor='#000000';this.borderColorDark='#9CBADE';this.borderColorLight='#9CBADE';"");}
		}
		}

		function meizzDayClick(n,ex) 
		{
		var yy=meizzTheYear;
		var mm = parseInt(meizzTheMonth)+ex;	
			if(mm<1){
				yy--;
				mm=12+mm;
			}
			else if(mm>12){
				yy++;
				mm=mm-12;
			}
			
		if (mm < 10){mm = ""0"" + mm;}
		if (outObject)
		{
			if (!n) {//outObject.value=""""; 
			return;}
			if ( n < 10){n = ""0"" + n;}
			outObject.value= yy + ""-"" + mm + ""-"" + n ; 
			closeLayer(); 
		}
		else {closeLayer(); alert(""您所要输出的控件对象并不存在!"");}
		}

       </script>
        ";
        #endregion
        private const string ScriptKey="HcTextBoxClientScrptKeyWord";
		/// <summary>
		/// 将此控件呈现给指定的输出参数。
		/// </summary>
		/// <param name="output"> 要写出到的 HTML 编写器 </param>
		
		protected override void OnPreRender(System.EventArgs e)
		{
			Page.RegisterStartupScript(ScriptKey,str_Js);
		}
		protected override void AddAttributesToRender(HtmlTextWriter output) 
		{
			output.AddAttribute("onfocus","setday(this);");
			if (this.write==false)
			{
				output.AddAttribute("onkeypress","return false;");
				output.AddAttribute("onselectstart","return false;");
                output.AddAttribute("onpaste", "return false;");
			}
			base.AddAttributesToRender(output);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -