分享
 
 
 

一个纯脚本写的日期控件

王朝asp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

使用的是一个img作为按钮,一个iframe载入日期页面

<IMG id="ImgDate" style="LEFT: 137px; CURSOR: hand; POSITION: absolute; TOP: 1px" onclick="SetlstDate1Visible('TxtDate')" src="images/ImgBtn/frmMainDate.gif" width="21">

<IFRAME class="dtpMonth1" id="lstDate1" style="DISPLAY: none; Z-INDEX: 105; LEFT: 112px; WIDTH: 176px; POSITION: absolute; TOP: 152px; HEIGHT: 160px"

tabIndex="-1" name="lstDate1" src="frmDate.aspx" frameBorder="0" scrolling="no">

</IFRAME>

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="frmDate.aspx.vb" Inherits="MOST_WEB.frmDate"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>

<HEAD>

<title>dtpDate1</title>

<meta http-equiv="Content-Type" content="text/html; charset=shift_jis">

<meta content="Microsoft Visual Studio .NET 7.0" name="GENERATOR">

<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">

<meta content="JavaScript" name="vs_defaultClientScript">

<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">

<LINK href="Styles.css" type="text/css" rel="stylesheet">

<script language="javascript" src="comFuncs.js"></script>

<script language="JavaScript">

function RunNian(The_Year)//取得是否為潤年

{

if ((The_Year%400==0) || ((The_Year%4==0) && (The_Year%100!=0)))

return true;

else

return false;

}

function GetWeekday(The_Year,The_Month)

{

var Allday;

Allday = 0;

if (The_Year>2000)

{

for (i=2000 ;i<The_Year; i++) //計算從2000年開始到今年的天數

{

if (RunNian(i)){

Allday += 366;

}else{

Allday += 365;

}

}

for (i=2; i<=The_Month; i++)

{

switch (i)

{

case 2 : Allday += 31; break;

case 3 :

if (RunNian(The_Year)){

Allday += 29;

}else{

Allday += 28;

}

break;

case 4 : Allday += 31; break;

case 5 : Allday += 30; break;

case 6 : Allday += 31; break;

case 7 : Allday += 30; break;

case 8 : Allday += 31; break;

case 9 : Allday += 31; break;

case 10 : Allday += 30; break;

case 11 : Allday += 31; break;

case 12 : Allday += 30; break;

}

}

}

return (Allday+6)%7;

}

function chooseday(objName,The_Year,The_Month,The_Day)

{

var Firstday;

Firstday = GetWeekday(The_Year,The_Month);//取得星期幾

ShowCalender(objName,The_Year,The_Month,The_Day);

}

function showdate(objName,The_Year,The_Month,The_Day){//顯示日期,將所選的日期傳到textbox中顯示出來

var txtDate;

objName="TxtDate";

txtDate= objName;

var completely_date;

var cur_Month

var cur_Day

if (The_Month.toString().length==1){//給月前面加0

cur_Month="0"+The_Month

}else{

cur_Month=The_Month

}

if (The_Day.toString().length==1){//給日期前加0

cur_Day="0"+The_Day

}else{

cur_Day=The_Day

}

if (The_Day!=0)//調整日期的樣式

completely_date = The_Year + "/" + cur_Month + "/" + cur_Day;

else

completely_date = "No Choose";

parent.document.all(txtDate).innerText = completely_date;//顯示給textbox

}

function nextmonth(objName,The_Year,The_Month,The_Day)//選擇下個月

{

if (The_Month==12)

chooseday(objName,The_Year+1,1,The_Day);

else

chooseday(objName,The_Year,The_Month+1,The_Day);

}

function prevmonth(objName,The_Year,The_Month,The_Day)//選擇上一月

{

if (The_Month==1)

chooseday(objName,The_Year-1,12,The_Day);

else

chooseday(objName,The_Year,The_Month-1,The_Day);

}

function closeself(){

top.document.frames(1).document.frames(1).ObjLostFocus();

}

function ShowCalender(objName,The_Year,The_Month,The_Day)//

{

var Firstday=GetWeekday(The_Year,The_Month);

var showstr;

var Month_Day; //顯示月的天數

var ShowMonth; //顯示月

var today; //當前天

var k=0

today = new Date();

switch (The_Month)//根據月來確定天數

{

case 1 : ShowMonth = "01"; Month_Day = 31; break;

case 2 :

ShowMonth = "02";

if (RunNian(The_Year))

Month_Day = 29;

else

Month_Day = 28;

break;

case 3 : ShowMonth = "03"; Month_Day = 31; break;

case 4 : ShowMonth = "04"; Month_Day = 30; break;

case 5 : ShowMonth = "05"; Month_Day = 31; break;

case 6 : ShowMonth = "06"; Month_Day = 30; break;

case 7 : ShowMonth = "07"; Month_Day = 31; break;

case 8 : ShowMonth = "08"; Month_Day = 31; break;

case 9 : ShowMonth = "09"; Month_Day = 30; break;

case 10 : ShowMonth = "10"; Month_Day = 31; break;

case 11 : ShowMonth = "11"; Month_Day = 30; break;

case 12 : ShowMonth = "12"; Month_Day = 31; break;

}

showstr = "";//葉面的樣式

showstr = "<Table class=calender HEIGHT=100% width=100% cellpadding=0 cellspacing=0 border=0 bordercolor=red align=center valign=top>";

showstr += "<tr height=20 class='title1'><td colspan=6>期日を選ぶ</td><td align=right><IMG style='CURSOR: hand' onclick='closeself()' height='15' src='./images/imgbtn/close.gif' width='15'></td></tr>";

showstr += "<tr height=20 class='title2'><td width=3><img style='cursor:hand' src='./images/imgbtn/btnLeft.gif' onclick=prevmonth('" + objName + "',"+The_Year+","+The_Month+","+The_Day+")></td><td align=left colspan=5>" + The_Year + "年"+ShowMonth+"月"+"</td><td align=right width=30 ><img style='cursor:hand' onclick=nextmonth('" + objName + "',"+The_Year+","+The_Month+","+The_Day+") src='./images/imgbtn/btnRight.gif'></td></tr>";

showstr += "<tr><td align=center width=100% colspan=7>";

showstr += "<table cellpadding=0 cellspacing=0 border=0 bordercolor=#999999 width=100%>";

showstr += "<Tr align=center class='title3'> ";

showstr += "<td class=sun>日</td>";

showstr += "<td>月</td>";

showstr += "<td>火</td>";

showstr += "<td>水</td>";

showstr += "<td>木</td>";

showstr += "<td>金</td>";

showstr += "<td class=sat>土</td>";

showstr += "</Tr><tr>"; //上面是設置完成日期的頭部

k=k+1;

for (i=1; i<=Firstday; i++) //Firstday傳過來的當前月第一天是星期幾

{

showstr += "<Td align=center class=day>&nbsp;</Td>"; //將前面的天數置空

}

if(The_Day>Month_Day)

{

The_Day=Month_Day; //用選擇的天The_Day和當前月天數Month_Day比較

}

for (i=1; i<=Month_Day; i++)

{

if (The_Day==i){

bgColor = "dayselected";

}else{

bgColor = "day";

}

if ((The_Year==today.getYear()) && (The_Month==today.getMonth()+1) && (i==today.getDate())){

showstr += "<td align=center class=" + bgColor + " style='CURSOR: hand;BACKGROUND-POSITION: center center;BACKGROUND-REPEAT: no-repeat;BACKGROUND-IMAGE: url(./Images/imgbtn/date.gif);' onclick=chooseday('" + objName + "'," + The_Year + "," + The_Month + "," + i + ")>" + i ;

}else{

showstr += "<td align=center class=" + bgColor + " style='cursor:hand' onclick=chooseday('" + objName + "'," + The_Year + "," + The_Month + "," + i + ")>" + i ;

}

showstr += "</td>";

Firstday = (Firstday + 1)%7;

if ((Firstday==0) && (i!=Month_Day)) {

showstr += "</tr><tr>";

k=k+1;

}

}

if (Firstday!=0) //Firstday傳過來的當前月第一天是星期幾

{

for (i=Firstday; i<7; i++)

showstr += "<td align=center class=day>&nbsp;</td>";

showstr += "</tr>";

}

showstr += "</tr><tr>"

if (k==5){

showstr += "<td colspan=7 class=day>&nbsp</td></tr><tr>";

}

var curMonth;

var curDay;

if ((today.getMonth()+1).toString().length==1){

curMonth="0"+(today.getMonth()+1);

}else{

curMonth=(today.getMonth()+1);

}

if (today.getDate().toString().length==1){

curDay="0"+today.getDate();

}else{

curDay=today.getDate();

}

showstr +="<td class='title4' colspan=2><img src='./Images/imgbtn/date.gif'></td><td align=left colspan=5 class='title4' style='CURSOR: hand;' onclick=getDtpDate('');>&nbsp 今日:"+today.getYear()+"/"+curMonth+"/"+curDay+"</td>"

showstr += "</tr></table></td></tr></table>";

document.all(objName).innerHTML= showstr;

showdate("txtFrom",The_Year,The_Month,The_Day)

}

function getDtpDate(strDate){

today = new Date();

if (!DcheckDate(strDate,"yyyy/mm/dd")){

The_Year = today.getYear();

The_Month = today.getMonth() + 1;

The_Day = today.getDate();

Firstday = GetWeekday(The_Year,The_Month);

}else{

var curday=new Date(strDate)

The_Year = curday.getYear();

The_Month = curday.getMonth() + 1;

The_Day = curday.getDate();

Firstday = GetWeekday(The_Year,The_Month);

}

ShowCalender("Date1",The_Year,The_Month,The_Day);

}

</script>

</HEAD>

<body>

<form id="Form1" method="post">

<TABLE style="LEFT: 0px; POSITION: absolute; TOP: 0px" cellSpacing="0" cellPadding="0"

border="0">

<TR>

<TD id="Date1"><FONT face="MS UI Gothic"></FONT></TD>

</TR>

</TABLE>

</form>

</body>

</HTML>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有