弹出式时间选择器


  1/*
  2****************************************************
  3功    能:时间选择控件
  4说    明:
  5版    本:1.0
  6创建时间:2005-8-16
  7***************************************************
  8*/

  9
 10<!--
 11var bMoveable=true;
 12//var _VersionInfo="(JavaScript)Version:2.0|2.0作者:walkingpoison|1.0作者: F.R.Huang(meizz)|MAIL: meizz@hzcnc.com|";
 13//_VersionInfo+="(Control)Version:1.0作者:Damao|MAIL: prettywolf@vip.sina.com";
 14var strFrame;
 15document.writeln('<iframe bgcolor="#000000" id=meizzDateLayer  frameborder=0 style="position: absolute;  width: 186; height: 247; z-index: 9998; display: none"></iframe>');
 16strFrame='<style>';
 17strFrame+='INPUT.button{BORDER-RIGHT: #B3C9E1 1px solid;BORDER-TOP: #B3C9E1 1px solid;BORDER-LEFT: #B3C9E1 1px solid;';
 18strFrame+='BORDER-BOTTOM: #ff9900 1px solid;BACKGROUND-COLOR: #EDF2F8;font-family:宋体;}
';
 19strFrame+='TD{FONT-SIZE: 9pt;font-family:宋体;}';
 20strFrame+='</style>';
 21strFrame+='<scr'+'ipt>';
 22strFrame+='var datelayerx,datelayery;';
 23strFrame+='var bDrag;    ';
 24strFrame+='function document.onmousemove()    ';
 25strFrame+='{if(bDrag && window.event.button==1)';
 26strFrame+='    {var DateLayer=parent.document.all.meizzDateLayer.style;';
 27strFrame+='        DateLayer.posLeft += window.event.clientX-datelayerx;';
 28strFrame+='        DateLayer.posTop += window.event.clientY-datelayery;}
}
';
 29strFrame+='function DragStart()        ';
 30strFrame+='{var DateLayer=parent.document.all.meizzDateLayer.style;';
 31strFrame+='    datelayerx=window.event.clientX;';
 32strFrame+='    datelayery=window.event.clientY;';
 33strFrame+='    bDrag=true;}
';
 34strFrame+='function DragEnd(){        ';
 35strFrame+='    bDrag=false;}
';
 36strFrame+='</scr'+'ipt>';
 37strFrame+='<div style="z-index:9999;position: absolute; left:0; top:0;" onselectstart="return false"><span id=tmpSelectYearLayer  style="z-index: 9999;position: absolute;top: 3; left: 19;display: none"></span>';
 38strFrame+='<span id=tmpSelectMonthLayer  style="z-index: 9999;position: absolute;top: 3; left: 78;display: none"></span>';
 39strFrame+='<table style="FILTER:dropshadow(color=#EDEDF8,offx=3.3,offy=3.3,positive=1);" cellSpacing="0" cellPadding="0" width="100%" border="0"><tr><td>';
 40strFrame+='<table border=1 cellspacing=0 cellpadding=0 width=182 height=160 bgColor="#FFFFFF" borderColorLight=#7197CA borderColorDark="#ffffff"  >';
 41strFrame+='  <tr ><td width=182 height=23  bgcolor=#FFFFFF><table border=0 cellspacing=1 cellpadding=0 width=180  height=23>';
 42strFrame+='      <tr align=center ><td width=16 align=center bgcolor=#B6CAE4 style="font-size:12px;cursor: hand;color: #ffffff" ';
 43strFrame+='        onclick="parent.meizzPrevM()" title="向前翻 1 月" ><>&lt;</b>';
 44strFrame+='        </td><td width=60 align=center style="font-size:12px;cursor:hand;"  ';
 45strFrame+='onmouseover="style.backgroundColor=\'#D7E1F0\'" onmouseout="style.backgroundColor=\'white\'" ';
 46strFrame+='onclick="parent.tmpSelectYearInnerHTML(this.innerText.substring(0,4))" title="点击这里选择年份"><span  id=meizzYearHead></span></td>';
 47strFrame+='<td width=48 align=center style="font-size:12px;cursor:hand;"  onmouseover="style.backgroundColor=\'#D7E1F0\'" ';
 48strFrame+=' onmouseout="style.backgroundColor=\'white\'" onclick="parent.tmpSelectMonthInnerHTML(this.innerText.length==3?this.innerText.substring(0,1):this.innerText.substring(0,2))"';
 49strFrame+='        title="点击这里选择月份"><span id=meizzMonthHead ></span></td>';
 50strFrame+='        <td width=16 bgcolor=#B6CAE4 align=center style="font-size:12px;cursor: hand;color: #ffffff" ';
 51strFrame+='         onclick="parent.meizzNextM()" title="向后翻 1 月" ><>&gt;</b></td></tr>';
 52strFrame+='    </table></td></tr>';
 53strFrame+='  <tr ><td width=180 height=18 >';
 54strFrame+='<table border=1 cellspacing=0 cellpadding=0 bgcolor=#618BC5 ' + (bMoveable? 'onmousedown="DragStart()" onmouseup="DragEnd()"':'');
 55strFrame+=' BORDERCOLORLIGHT=#3677b1 bgcolor=#5168C8 BORDERCOLORDARK=#FFFFFF width="100%" height=25  style="cursor:' + (bMoveable ? 'move':'default') + '">';
 56strFrame+='<tr  valign="middle" align="center"><td style="font-size:12px;color:#FFFFFF" ><b></b></td>';
 57strFrame+='<td style="font-size:12px;color:#FFFFFF"  ><b></b></td><td style="font-size:12px;color:#FFFFFF" ><b></b></td>';
 58strFrame+='<td style="font-size:12px;color:#FFFFFF" ><b></b></td><td style="font-size:12px;color:#FFFFFF" ><b></b></td>';
 59strFrame+='<td style="font-size:12px;color:#FFFFFF"   ><b></b></td><td style="font-size:12px;color:#FFFFFF" ><b></b></td></tr>';
 60strFrame+='</table></td></tr>';
 61strFrame+='  <tr ><td width="100%" height=120 >';
 62strFrame+='    <table border=1 cellspacing=2 cellpadding=0 borderColorDark=#ffffff bgColor=#FFFFFF borderColorLight=#83A4D1 width="100%" height=120 >';
 63var n=0for (j=0;j<5;j++){ strFrame+= ' <tr align=center >'; for (i=0;i<7;i++){
 64strFrame+='<td width=25 height=25 id=meizzDay'+n+' style="font-size:12px"  onclick=parent.meizzDayClick(this.innerText,0)></td>';n++;}

 65strFrame+='</tr>';}

 66strFrame+='      <tr align=center >';
 67for (i=35;i<39;i++)strFrame+='<td width=25 height=25 id=meizzDay'+i+' style="font-size:12px"  onclick="parent.meizzDayClick(this.innerText,0)"></td>';
 68strFrame+='        <td colspan=3 align=right ><span onclick=parent.closeLayer() style="font-size:12px;cursor: hand"';
 69strFrame+='          title="关闭时间选择"><u>关闭</u></span>&nbsp;</td></tr>';
 70strFrame+='    </table></td></tr><tr ><td >';
 71strFrame+='        <table border=0 cellspacing=1 cellpadding=0 width=100%  bgcolor=#FFFFFF>';
 72strFrame+='          <tr ><td  align=left><input  type=button class=button style="cursor:hand" value="<<" title="向前翻 1 年" onclick="parent.meizzPrevY()" ';
 73strFrame+='             onfocus="this.blur()" style="font-size: 12px; height: 20px"><input  class=button title="向前翻 1 月" type=button ';
 74strFrame+='             value="" style="cursor:hand" onclick="parent.meizzPrevM()" onfocus="this.blur()" style="font-size: 12px; height: 20px"></td><td ';
 75strFrame+='              align=center><input  style="cursor:hand"  type=button class=button value="今日" onclick="parent.meizzToday()" ';
 76strFrame+='             onfocus="this.blur()" title="当前日期" style="font-size: 12px; height: 20px; cursor:hand"></td><td ';
 77//added by wayne @050816 
 78strFrame+='              align=center><input  style="cursor:hand"  type=button class=button value="清空" onclick="parent.ClearDate()" ';
 79strFrame+='             onfocus="this.blur()" title="清除日期" style="font-size: 12px; height: 20px; cursor:hand"></td><td ';
 80
 81strFrame+='              align=right><input  type=button class=button value=" >" style="cursor:hand" onclick="parent.meizzNextM()" ';
 82strFrame+='             onfocus="this.blur()" title="向后翻 1 月" class=button style="font-size: 12px; height: 20px"><input ';
 83strFrame+='              type=button class=button style="cursor:hand" value=">>" title="向后翻 1 年" onclick="parent.meizzNextY()"';
 84strFrame+='             onfocus="this.blur()" style="font-size: 12px; height: 20px"></td>';
 85strFrame+='</tr></table></td></tr></table></td></tr></table></div>';
 86window.frames.meizzDateLayer.document.writeln(strFrame);
 87window.frames.meizzDateLayer.document.close();
 88var outObject;
 89var outButton;
 90var outDate="";
 91var odatelayer=window.frames.meizzDateLayer.document.all;
 92
 93function setday(tt,obj){
 94    if (arguments.length >  2){alert("对不起!传入本控件的参数太多!");return;}
 95    if (arguments.length == 0){alert("对不起!您没有传回本控件任何参数!");return;}
 96    var dads  = document.all.meizzDateLayer.style;
 97    var th = tt;
 98    var ttop  = tt.offsetTop;     
 99    var thei  = tt.clientHeight;  
100    var tleft = tt.offsetLeft;    
101    var ttyp  = tt.type;          
102    while (tt = tt.offsetParent){ttop+=tt.offsetTop; tleft+=tt.offsetLeft;}
103    dads.top  = (ttyp=="image")? ttop+thei : ttop+thei+6;
104    dads.left = tleft;
105    outObject = (arguments.length == 1? th : obj;
106    outButton = (arguments.length == 1? null : th;    
107    var reg = /^(\d+)-(\d{1,2})-(\d{1,2})$/
108    var r = outObject.value.match(reg); 
109    if(r!=null){
110        r[2]=r[2]-1
111        var d= new Date(r[1], r[2],r[3]); 
112        if(d.getFullYear()==r[1&& d.getMonth()==r[2&& d.getDate()==r[3]){
113            outDate=d;
114        }

115        else outDate="";
116            meizzSetDay(r[1],r[2]+1);
117    }

118    else{
119        outDate="";
120        meizzSetDay(new Date().getFullYear(), new Date().getMonth() + 1);
121    }

122    dads.display = '';
123    event.returnValue=false;
124}

125var MonHead = new Array(12);
126    MonHead[0= 31; MonHead[1= 28; MonHead[2= 31; MonHead[3= 30; MonHead[4]  = 31; MonHead[5]  = 30;
127    MonHead[6= 31; MonHead[7= 31; MonHead[8= 30; MonHead[9= 31; MonHead[10= 30; MonHead[11= 31;
128var meizzTheYear=new Date().getFullYear(); 
129var meizzTheMonth=new Date().getMonth()+1
130var meizzWDay=new Array(39);
131
132//判断是否隐藏显示出来的时间显示层
133function document.onclick()
134
135    with(window.event)
136    
137        if (srcElement != outObject && srcElement != outButton)
138            closeLayer();
139    }

140}

141function document.onkeyup(){
142    if (window.event.keyCode==27){
143        if(outObject)outObject.blur();
144        closeLayer();
145    }

146    else if(document.activeElement)
147        if(document.activeElement != outObject && document.activeElement != outButton)
148        {closeLayer();}
149}

150function meizzWriteHead(yy,mm){
151    odatelayer.meizzYearHead.innerText  = yy + " 年";
152    odatelayer.meizzMonthHead.innerText = mm + " 月";
153}

154function tmpSelectYearInnerHTML(strYear){
155if (strYear.match(/\D/)!=null){alert("年份输入参数不是数字!");return;}
156var m = (strYear) ? strYear : new Date().getFullYear();
157if (m < 1000 || m > 9999{alert("年份值不在 1000 到 9999 之间!");return;}
158//年份选择起始
159var n = m - 65;
160if (n < 1000) n = 1000;
161if (n + 71 > 9999) n = 9929;
162var s = "&nbsp;&nbsp;&nbsp;    <select  name=tmpSelectYear style='font-size: 12px' "
163    s += "onblur='document.all.tmpSelectYearLayer.style.display=\"none\""
164    s += "onchange='document.all.tmpSelectYearLayer.style.display=\"none\";"
165    s += "parent.meizzTheYear = this.value; parent.meizzSetDay(parent.meizzTheYear,parent.meizzTheMonth)'>\r\n";
166var selectInnerHTML = s;
167for (var i = n; i < n + 71; i++){
168    if (i == m)
169    {selectInnerHTML += "<option  value='" + i + "' selected>" + i + "" + "</option>\r\n";}
170    else {selectInnerHTML += "<option  value='" + i + "'>" + i + "" + "</option>\r\n";}
171}

172selectInnerHTML += "</select>";
173odatelayer.tmpSelectYearLayer.style.display="";
174odatelayer.tmpSelectYearLayer.innerHTML = selectInnerHTML;
175odatelayer.tmpSelectYear.focus();
176}

177function tmpSelectMonthInnerHTML(strMonth){
178if (strMonth.match(/\D/)!=null){alert('月份输入参数不是数字!');return;} 
179var m = (strMonth) ? strMonth : new Date().getMonth() + 1;
180var s = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select  name=tmpSelectMonth style='font-size: 12px' "
181    s += "onblur='document.all.tmpSelectMonthLayer.style.display=\"none\""
182    s += "onchange='document.all.tmpSelectMonthLayer.style.display=\"none\";"
183    s += "parent.meizzTheMonth = this.value; parent.meizzSetDay(parent.meizzTheYear,parent.meizzTheMonth)'>\r\n ";
184var selectInnerHTML = s;
185for (var i = 1; i < 13; i++){
186    if (i == m)
187    {selectInnerHTML += "<option  value='"+i+"' selected>"+i+""+"</option>\r\n";}
188    else {selectInnerHTML += "<option  value='"+i+"'>"+i+""+"</option>\r\n";}
189}

190selectInnerHTML += "</select>";
191odatelayer.tmpSelectMonthLayer.style.display="";
192odatelayer.tmpSelectMonthLayer.innerHTML = selectInnerHTML;
193odatelayer.tmpSelectMonth.focus();
194}

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

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

201function GetMonthCount(year,month){
202    var c=MonHead[month-1];if((month==2)&&IsPinYear(year)) c++;return c;
203}

204function GetDOW(day,month,year){
205    var dt=new Date(year,month-1,day).getDay()/7return dt;
206}

207function meizzPrevY(){
208    if(meizzTheYear > 999 && meizzTheYear <10000){meizzTheYear--;}
209    else{alert("年份超出范围(1000-9999)!");}
210    meizzSetDay(meizzTheYear,meizzTheMonth);
211}

212function meizzNextY(){
213    if(meizzTheYear > 999 && meizzTheYear <10000){meizzTheYear++;}
214    else{alert("年份超出范围(1000-9999)!");}
215    meizzSetDay(meizzTheYear,meizzTheMonth);
216}

217function meizzToday(){
218    var today;
219    meizzTheYear = new Date().getFullYear();
220    meizzTheMonth = new Date().getMonth()+1;
221    today=new Date().getDate();
222    if(outObject){
223        outObject.value=meizzTheYear + "-" + meizzTheMonth + "-" + today;
224    }

225    closeLayer();
226}

227
228//added by wayne 050816
229//ClearDate
230function ClearDate(){
231    if(outObject){
232        outObject.value="";
233    }

234    closeLayer();
235}

236
237function meizzPrevM(){
238    if(meizzTheMonth>1){meizzTheMonth--}else{meizzTheYear--;meizzTheMonth=12;}
239    meizzSetDay(meizzTheYear,meizzTheMonth);
240}

241function meizzNextM(){
242    if(meizzTheMonth==12){meizzTheYear++;meizzTheMonth=1}else{meizzTheMonth++}
243    meizzSetDay(meizzTheYear,meizzTheMonth);
244}

245function meizzSetDay(yy,mm){
246meizzWriteHead(yy,mm);
247meizzTheYear=yy;
248meizzTheMonth=mm;
249for (var i = 0; i < 39; i++){meizzWDay[i]=""}
250var day1 = 1,day2=1,firstday = new Date(yy,mm-1,1).getDay();
251for (i=0;i<firstday;i++)meizzWDay[i]=GetMonthCount(mm==1?yy-1:yy,mm==1?12:mm-1)-firstday+i+1
252for (i = firstday; day1 < GetMonthCount(yy,mm)+1; i++){meizzWDay[i]=day1;day1++;}
253for (i=firstday+GetMonthCount(yy,mm);i<39;i++){meizzWDay[i]=day2;day2++}
254for (i = 0; i < 39; i++)
255var da = eval("odatelayer.meizzDay"+i)
256    if (meizzWDay[i]!="")
257        da.borderColorLight="#76A0CF";
258        da.borderColorDark="#76A0CF";
259        if(i<firstday){
260            da.innerHTML="<font style=' color: #B5C5D2;'>" + meizzWDay[i] + "</font>";
261            da.title=(mm==1?12:mm-1+"" + meizzWDay[i] + "";
262            da.onclick=Function("meizzDayClick(this.innerText,-1)");
263            if(!outDate)
264                da.style.backgroundColor = ((mm==1?yy-1:yy) == new Date().getFullYear() && 
265                    (mm==1?12:mm-1== new Date().getMonth()+1 && meizzWDay[i] == new Date().getDate()) ?
266                    "#E4E3F2":"#FFFFFF";
267            else{
268                da.style.backgroundColor =((mm==1?yy-1:yy)==outDate.getFullYear() && (mm==1?12:mm-1)== outDate.getMonth() + 1 && 
269                meizzWDay[i]==outDate.getDate())? "#E8F5E7" : 
270                (((mm==1?yy-1:yy) == new Date().getFullYear() && (mm==1?12:mm-1== new Date().getMonth()+1 && 
271                meizzWDay[i] == new Date().getDate()) ? "#E4E3F2":"#FFFFFF"); 
272                if((mm==1?yy-1:yy)==outDate.getFullYear() && (mm==1?12:mm-1)== outDate.getMonth() + 1 && 
273                meizzWDay[i]==outDate.getDate())
274                {}
275            }

276        }

277        else if (i>=firstday+GetMonthCount(yy,mm)){
278            da.innerHTML="<font style=' color: #B5C5D2;'>" + meizzWDay[i] + "</font>";
279            da.title=(mm==12?1:mm+1+"" + meizzWDay[i] + "";
280            da.onclick=Function("meizzDayClick(this.innerText,1)");
281            if(!outDate)
282                da.style.backgroundColor = ((mm==12?yy+1:yy) == new Date().getFullYear() && 
283                    (mm==12?1:mm+1== new Date().getMonth()+1 && meizzWDay[i] == new Date().getDate()) ?
284                    "#E4E3F2":"#FFFFFF";
285            else{
286                da.style.backgroundColor =((mm==12?yy+1:yy)==outDate.getFullYear() && (mm==12?1:mm+1)== outDate.getMonth() + 1 && 
287                meizzWDay[i]==outDate.getDate())? "#E8F5E7" : 
288                (((mm==12?yy+1:yy) == new Date().getFullYear() && (mm==12?1:mm+1== new Date().getMonth()+1 && 
289                meizzWDay[i] == new Date().getDate()) ? "#E4E3F2":"#FFFFFF"); 
290                if((mm==12?yy+1:yy)==outDate.getFullYear() && (mm==12?1:mm+1)== outDate.getMonth() + 1 && 
291                meizzWDay[i]==outDate.getDate()){
292                    da.borderColorLight="#E4E3F2";
293                    da.borderColorDark="#E4E3F2";  
294                }

295            }

296        }

297        else{
298            da.innerHTML="<font style=' color: #3E5468;'>" + meizzWDay[i] + "</FONT>";
299            da.title=mm +"" + meizzWDay[i] + "";
300            da.onclick=Function("meizzDayClick(this.innerText,0)");
301            if(!outDate)
302                da.style.backgroundColor = (yy == new Date().getFullYear() && mm == new Date().getMonth()+1 && meizzWDay[i] == new Date().getDate())?
303                    "#FFFFFF":"#FFFFFF";
304            else{
305                da.style.backgroundColor =(yy==outDate.getFullYear() && mm== outDate.getMonth() + 1 && meizzWDay[i]==outDate.getDate())?
306                    "#D5ECD2":((yy == new Date().getFullYear() && mm == new Date().getMonth()+1 && meizzWDay[i] == new Date().getDate())?
307                    "#E4E3F2":"#F8F8FC"); 
308            }

309        }

310        da.style.cursor="hand"
311        da.onmouseover=Function("this.backgroundColor='#000000';this.borderColorDark='#000099';this.borderColorLight='#000099';");
312        da.onmouseout=Function("this.bgColor='#000000';this.borderColorDark='#9CBADE';this.borderColorLight='#9CBADE';");
313    }

314    else{da.innerHTML="";da.style.backgroundColor="";da.style.cursor="default";da.onmouseover=Function("this.backgroundColor='#000000';this.borderColorDark='#000099';this.borderColorLight='#000099';");
315        da.onmouseout=Function("this.bgColor='#000000';this.borderColorDark='#9CBADE';this.borderColorLight='#9CBADE';");}

316}
}

317function meizzDayClick(n,ex){
318var yy=meizzTheYear;
319var mm = parseInt(meizzTheMonth)+ex;    
320    if(mm<1){
321        yy--;
322        mm=12+mm;
323    }

324    else if(mm>12){
325        yy++;
326        mm=mm-12;
327    }

328if (mm < 10){mm = "0" + mm;}
329if (outObject){
330    if (!n) 
331    return;}

332    if ( n < 10){n = "0" + n;}
333    outObject.value= yy + "-" + mm + "-" + n ;
334    closeLayer();
335    outObject.onchange();
336}

337else {closeLayer(); alert("您所要输出的控件对象并不存在!");}
338}

339//-->

<!--.aspx文件中的调用方法//-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
    
<HEAD>
        
<title>
            
<asp:Literal id="PageTitle" runat="server"></asp:Literal></title>
        
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
        
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
        
<meta content="JavaScript" name="vs_defaultClientScript">
        
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
        
<LINK href="../Styles/EasyStyle.css" type="text/css" rel="stylesheet">
                
<script language="javascript" src="../Scripts/EasyDate.js"></script>
        
    
</HEAD>
    
<body class="BodyStyle" MS_POSITIONING="GridLayout">

<asp:textbox id="txtEndDate" style="CURSOR: hand" onfocus="setday(this);" runat="server" CssClass="allborderW" Width="75px" ReadOnly="True">
posted @ 2005-12-30 14:50  blueKnight  Views(580)  Comments(0Edit  收藏  举报