calendar.js<script>Now = new Date(); NowDay = Now.getDate(); NowMonth = Now.getMonth(); NowYear = Now.getYear(); if (NowYear < 2000) NowYear += 1900; //for Netscape//function for returning how many days there are in a month including leap years function DaysInMonth(WhichMonth, WhichYear) { var DaysInMonth = 31; if (WhichMonth == "Apr" || WhichMonth == "Jun" || WhichMonth == "Sep" || WhichMonth == "Nov") DaysInMonth = 30; if (WhichMonth == "Feb" && (WhichYear/4) != Math.floor(WhichYear/4)) DaysInMonth = 28; if (WhichMonth == "Feb" && (WhichYear/4) == Math.floor(WhichYear/4)) DaysInMonth = 29; return DaysInMonth; }//function to change the available days in a months function ChangeOptionDays(Which) { DaysObject = eval("document.frmSearch." + Which + "Day"); MonthObject = eval("document.frmSearch." + Which + "Month"); YearObject = eval("document.frmSearch." + Which + "Year"); Month = MonthObject[MonthObject.selectedIndex].text; Year = YearObject[YearObject.selectedIndex].text; DaysForThisSelection = DaysInMonth(Month, Year); CurrentDaysInSelection = DaysObject.length; if (CurrentDaysInSelection > DaysForThisSelection) { for (i=0; i<(CurrentDaysInSelection-DaysForThisSelection); i++) { DaysObject.options[DaysObject.options.length - 1] = null } } if (DaysForThisSelection > CurrentDaysInSelection) { for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++) { NewOption = new Option(DaysObject.options.length + 1); DaysObject.add(NewOption); } } if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0; }//function to set options to today function SetToToday(Which) { DaysObject = eval("document.frmSearch." + Which + "Day"); MonthObject = eval("document.frmSearch." + Which + "Month"); YearObject = eval("document.frmSearch." + Which + "Year"); YearObject[0].selected = true; MonthObject[NowMonth].selected = true; ChangeOptionDays(Which); DaysObject[NowDay-1].selected = true; }//function to write option years plus x function WriteYearOptions(YearsAhead) { line = ""; for (i=0; i<YearsAhead; i++) { line += "<OPTION>"; line += NowYear - i; } return line; } // End --> </script>
可以,或者直接调用控件,有javascript做的,有的直接调用ms的时间控件
<table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td>
<input type="checkbox" id=OOO name="dateOptions" value="1" onclick="popUp(document.all.searchDate)">
日期<br>
<script>
function popUp(themenu) {
newX = window.event.x + document.body.scrollLeft
newY = window.event.y + document.body.scrollTop
menu = themenu;
if ( menu.style.display == ""){
menu.style.display = "none" }
else {
menu.style.display = ""}
menu.style.pixelLeft = newX - 50
menu.style.pixelTop = newY - 50
}
function adjustDateScope(selectedE){
if(selectedE.value == 1){
document.frmSearch.scope.disabled=true;
document.frmSearch.beforeDay.disabled=true;
document.frmSearch.beforeMonth.disabled=true; document.frmSearch.FirstSelectDay.disabled=true;
document.frmSearch.FirstSelectMonth.disabled=true;
document.frmSearch.FirstSelectYear.disabled=true;
document.frmSearch.SecondSelectDay.disabled=true;
document.frmSearch.SecondSelectMonth.disabled=true;
document.frmSearch.SecondSelectYear.disabled=true;
}else if(selectedE.value==0){
document.frmSearch.scope.disabled=false;
document.frmSearch.beforeDay.disabled=false;
document.frmSearch.beforeMonth.disabled=false; document.frmSearch.FirstSelectDay.disabled=false;
document.frmSearch.FirstSelectMonth.disabled=false;
document.frmSearch.FirstSelectYear.disabled=false;
document.frmSearch.SecondSelectDay.disabled=false;
document.frmSearch.SecondSelectMonth.disabled=false;
document.frmSearch.SecondSelectYear.disabled=false;
adjustDateScope2();
}
}
function adjustDateScope2(){
if(document.frmSearch.scope[0].checked==true) asdf=1;
if(document.frmSearch.scope[1].checked==true) asdf=2;
if(document.frmSearch.scope[2].checked==true) asdf=3;
Vscope=asdf;
if(Vscope==1){
document.frmSearch.beforeMonth.disabled=false;
document.frmSearch.beforeDay.disabled=true;
document.frmSearch.FirstSelectDay.disabled=true;
document.frmSearch.FirstSelectMonth.disabled=true;
document.frmSearch.FirstSelectYear.disabled=true;
document.frmSearch.SecondSelectDay.disabled=true;
document.frmSearch.SecondSelectMonth.disabled=true;
document.frmSearch.SecondSelectYear.disabled=true;
}else if(Vscope==2){
document.frmSearch.beforeDay.disabled=false;
document.frmSearch.beforeMonth.disabled=true;
document.frmSearch.FirstSelectDay.disabled=true;
document.frmSearch.FirstSelectMonth.disabled=true;
document.frmSearch.FirstSelectYear.disabled=true;
document.frmSearch.SecondSelectDay.disabled=true;
document.frmSearch.SecondSelectMonth.disabled=true;
document.frmSearch.SecondSelectYear.disabled=true;
}else if(Vscope==3){
document.frmSearch.FirstSelectDay.disabled=false;
document.frmSearch.FirstSelectMonth.disabled=false;
document.frmSearch.FirstSelectYear.disabled=false;
document.frmSearch.SecondSelectDay.disabled=false;
document.frmSearch.SecondSelectMonth.disabled=false;
document.frmSearch.SecondSelectYear.disabled=false; document.frmSearch.beforeMonth.disabled=true;
document.frmSearch.beforeDay.disabled=true;
}
}
</script>
<table width="98%" id=searchDate class=box style="display:none" border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<td>
<select name="whichplace" onchange="adjustDateScope(document.frmSearch.whichplace)" readonly disabled>
<option value="1">创建的实体</option>
<option value="1">最近打开过的实体</option>
</select>
<br>
<input type="radio" name="scope" value="1" onclick="adjustDateScope2()" checked>
前
<select name="beforeMonth" size="1" Xmultiple>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
</select>
个月 <br>
<input type="radio" name="scope" value="2" onclick="adjustDateScope2()">
前
<select name="beforeDay" size="1" Xmultiple>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
</select>
天<br>
<input type="radio" name="scope" value="3" onclick="adjustDateScope2()">
介于
<br> <script language="JavaScript" src=calendar.js></script><SELECT name="FirstSelectDay">
</SELECT>
<SELECT name="FirstSelectMonth" onchange="ChangeOptionDays('FirstSelect')">
<OPTION value=1>Jan
<OPTION value=2>Feb
<OPTION value=3>Mar
<OPTION value=4>Apr
<OPTION value=5>May
<OPTION value=6>Jun
<OPTION value=7>Jul
<OPTION value=8>Aug
<OPTION value=9>Sep
<OPTION value=10>Oct
<OPTION value=11>Nov
<OPTION value=12>Dec
</SELECT>
<SELECT name="FirstSelectYear" onchange="ChangeOptionDays('FirstSelect')">
<SCRIPT language="JavaScript">
document.write(WriteYearOptions(5));
</SCRIPT>
</SELECT> <br>
和
<SELECT name="SecondSelectDay">
</SELECT>
<SELECT name="SecondSelectMonth" onchange="ChangeOptionDays('SecondSelect')">
<OPTION value=1>Jan
<OPTION value=2>Feb
<OPTION value=3>Mar
<OPTION value=4>Apr
<OPTION value=5>May
<OPTION value=6>Jun
<OPTION value=7>Jul
<OPTION value=8>Aug
<OPTION value=9>Sep
<OPTION value=10>Oct
<OPTION value=11>Nov
<OPTION value=12>Dec
</SELECT>
<SELECT name="SecondSelectYear" onchange="ChangeOptionDays('SecondSelect')">
<SCRIPT language="JavaScript">
document.write(WriteYearOptions(5));
SetToToday('FirstSelect');SetToToday('SecondSelect');
</SCRIPT>
</SELECT>
<br>
</td>
</tr>
</table>
</form>
NowDay = Now.getDate();
NowMonth = Now.getMonth();
NowYear = Now.getYear();
if (NowYear < 2000) NowYear += 1900; //for Netscape//function for returning how many days there are in a month including leap years
function DaysInMonth(WhichMonth, WhichYear)
{
var DaysInMonth = 31;
if (WhichMonth == "Apr" || WhichMonth == "Jun" || WhichMonth == "Sep" || WhichMonth == "Nov") DaysInMonth = 30;
if (WhichMonth == "Feb" && (WhichYear/4) != Math.floor(WhichYear/4)) DaysInMonth = 28;
if (WhichMonth == "Feb" && (WhichYear/4) == Math.floor(WhichYear/4)) DaysInMonth = 29;
return DaysInMonth;
}//function to change the available days in a months
function ChangeOptionDays(Which)
{
DaysObject = eval("document.frmSearch." + Which + "Day");
MonthObject = eval("document.frmSearch." + Which + "Month");
YearObject = eval("document.frmSearch." + Which + "Year"); Month = MonthObject[MonthObject.selectedIndex].text;
Year = YearObject[YearObject.selectedIndex].text; DaysForThisSelection = DaysInMonth(Month, Year);
CurrentDaysInSelection = DaysObject.length;
if (CurrentDaysInSelection > DaysForThisSelection)
{
for (i=0; i<(CurrentDaysInSelection-DaysForThisSelection); i++)
{
DaysObject.options[DaysObject.options.length - 1] = null
}
}
if (DaysForThisSelection > CurrentDaysInSelection)
{
for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++)
{
NewOption = new Option(DaysObject.options.length + 1);
DaysObject.add(NewOption);
}
}
if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0;
}//function to set options to today
function SetToToday(Which)
{
DaysObject = eval("document.frmSearch." + Which + "Day");
MonthObject = eval("document.frmSearch." + Which + "Month");
YearObject = eval("document.frmSearch." + Which + "Year"); YearObject[0].selected = true;
MonthObject[NowMonth].selected = true; ChangeOptionDays(Which); DaysObject[NowDay-1].selected = true;
}//function to write option years plus x
function WriteYearOptions(YearsAhead)
{
line = "";
for (i=0; i<YearsAhead; i++)
{
line += "<OPTION>";
line += NowYear - i;
}
return line;
}
// End -->
</script>