---
title: "点击文本框弹出日期"
author: "iammonster"
date: "2007-10-15T13:21:00Z"
tags: []
slug: "untitled"
draft: false
lastmod: "2007-10-15T13:21:00Z"
id: 273293
url: "https://jiajun.iteye.com/blog/273293"
---

JS文件（birthday.js）： 

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)// JavaScript Document  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)//日历  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)var date\_start,date\_end,g\_object  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)var today = new Date();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)var separator="-";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)var inover=false;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)//mode :时间变换的类型0-年 1-月 2-直接选择月  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)function change\_date(temp,mode)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)var t\_month,t\_year  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)if (mode)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if(mode==1)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)t\_month=parseInt(cele\_date\_month.value,10)+parseInt(temp,10);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)else  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)t\_month=parseInt(temp)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)if (t\_month&lt;cele\_date\_month.options(0).text) ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)cele\_date\_month.value=cele\_date\_month.options(cele\_date\_month.length-1).text;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)change\_date(parseInt(cele\_date\_year.value,10)-1,0);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)else...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)if (t\_month&gt;cele\_date\_month.options(cele\_date\_month.length-1).text)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)cele\_date\_month.value=cele\_date\_month.options(0).text;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)change\_date(parseInt(cele\_date\_year.value,10)+1,0);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)else  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)...{cele\_date\_month.value=t\_month;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)set\_cele\_date(cele\_date\_year.value,cele\_date\_month.value);   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)else...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)t\_year=parseInt(temp,10);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)if (t\_year&lt;cele\_date\_year.options(0).text) ...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)cele\_date\_year.value=cele\_date\_year.options(0).text;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)set\_cele\_date(cele\_date\_year.value,1);   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)else...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)if (parseInt(t\_year,10)&gt;parseInt(cele\_date\_year.options(cele\_date\_year.length-1).text,10))...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)cele\_date\_year.value=cele\_date\_year.options(cele\_date\_year.length-1).text;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)set\_cele\_date(cele\_date\_year.value,12);   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)else  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)...{cele\_date\_year.value=t\_year;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)set\_cele\_date(cele\_date\_year.value,cele\_date\_month.value);   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)window.cele\_date.focus();  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)//初始化日历  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)function init(d\_start,d\_end)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)var temp\_str;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)var i=0  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)var j=0  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)date\_start=new Date(1980,7,1)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)date\_end=new Date(2004,8,1)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)document.writeln("&lt;div name="cele\_date" id="cele\_date" style="display:none" style="LEFT: 69px; POSITION: absolute; TOP: 159px;Z-INDEX:99" onClick="event.cancelBubble=true;" onBlur="hilayer()" onMouseout="lostlayerfocus()"&gt;-&lt;/div&gt;");  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)window.cele\_date.innerHTML="";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)temp\_str="&lt;table border="1" bgcolor="#DDDDDD" bordercolor="white"&gt;&lt;tr&gt;&lt;td colspan=7 onmouseover="overcolor(this)"&gt;";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)temp\_str+="&lt;input type="Button" value="&lt;&lt;" onclick="change\_date(-1,1)" onmouseover="getlayerfocus()" style="color: #000099; background-color: #BFBFBF; cursor: hand"&gt;-";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)temp\_str+=""  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)temp\_str+="&lt;select name="cele\_date\_year" id="cele\_date\_year" language="javascript" onchange="change\_date(this.value,0)" onmouseover="getlayerfocus()" onblur="getlayerfocus()" style="font-size: 9pt; border: 1px #666666 outset; background-color: #F4F8FB"&gt;"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)for (i=1900;i&lt;=2020;i++)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)temp\_str+="&lt;OPTION value=""+i.toString()+""&gt;"+i.toString()+"&lt;/OPTION&gt;";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)temp\_str+="&lt;/select&gt;-";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)temp\_str+=""  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)temp\_str+="&lt;select name="cele\_date\_month" id="cele\_date\_month" language="javascript" onchange="change\_date(this.value,2)" onmouseover="getlayerfocus()" onblur="getlayerfocus()" style="font-size: 9pt; border: 1px #666666 outset; background-color: #F4F8FB"&gt;"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)for (i=1;i&lt;=12;i++)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)temp\_str+="&lt;OPTION value=""+i.toString()+""&gt;"+i.toString()+"&lt;/OPTION&gt;";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)temp\_str+="&lt;/select&gt;-";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)temp\_str+=""  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)temp\_str+="&lt;input type="Button" value="&gt;&gt;" onclick="change\_date(1,1)" onmouseover="getlayerfocus()" style="color: #000099; background-color: #BFBFBF; cursor: hand"&gt;";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)temp\_str+="&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td onmouseover="overcolor(this)"&gt;"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)temp\_str+="&lt;font color=red&gt;日&lt;/font&gt;&lt;/td&gt;&lt;td&gt;";temp\_str+="一&lt;/td&gt;&lt;td&gt;"; temp\_str+="二&lt;/td&gt;&lt;td&gt;"; temp\_str+="三&lt;/td&gt;&lt;td&gt;"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)temp\_str+="四&lt;/td&gt;&lt;td&gt;";temp\_str+="五&lt;/td&gt;&lt;td&gt;"; temp\_str+="六&lt;/td&gt;&lt;/tr&gt;";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)for (i=1 ;i&lt;=6 ;i++)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)temp\_str+="&lt;tr&gt;";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)for(j=1;j&lt;=7;j++)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)temp\_str+="&lt;td name="c"+i+"\_"+j+""id="c"+i+"\_"+j+"" style="CURSOR: hand" style="COLOR:#000000" language="javascript" onmouseover="overcolor(this)" onmouseout="outcolor(this)" onclick="td\_click(this)"&gt;?&lt;/td&gt;"  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)temp\_str+="&lt;/tr&gt;"   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)temp\_str+="&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;";  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)window.cele\_date.innerHTML=temp\_str;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)function set\_cele\_date(year,month)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)var i,j,p,k  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)var nd=new Date(year,month-1,1);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)event.cancelBubble=true;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)cele\_date\_year.value=year;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)cele\_date\_month.value=month;   
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)k=nd.getDay()-1  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)var temp;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)for (i=1;i&lt;=6;i++)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)for(j=1;j&lt;=7;j++)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)eval("c"+i+"\_"+j+".innerHTML=""");  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)eval("c"+i+"\_"+j+".bgColor="#DDDDDD"");  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)eval("c"+i+"\_"+j+".style.cursor="hand"");  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)while(month-1==nd.getMonth())  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)...{ j=(nd.getDay() +1);  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)p=parseInt((nd.getDate()+k) / 7)+1;  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)eval("c"+p+"\_"+j+".innerHTML="+"""+nd.getDate()+""");  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)if ((nd.getDate()==today.getDate())&&(cele\_date\_month.value==today.getMonth()+1)&&(cele\_date\_year.value==today.getYear()))...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)eval("c"+p+"\_"+j+".bgColor="#EFFB64"");  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)if (nd&gt;date\_end || nd&lt;date\_start)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)...{  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)eval("c"+p+"\_"+j+".bgColor="#FF9999"");  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)eval("c"+p+"\_"+j+".style.cursor="text"");  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)nd=new Date(nd.valueOf() + 86400000)  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)}  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)//续  
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)