Goals:
There are two dates in the drop-down box:
Copy codeThe Code is as follows:
<Head>
// Import the jquery address
<Script src = "(Jquery address)" language = "JavaScript" type = "text/javascript"> </script>
<Script type = "text/javascript">
// StartYear changed
Function changeYear (str, isstart)
{
Var pre = "start ";
If (isstart = false)
{
Pre = "end ";
}
Var startMonth = $ (pre + "Month"). value;
If (startMonth = "")
{
Var e = $ (pre + "Month ");
OptionClear (e );
Return;
}
Var n = MonHead [startMonth-1];
If (startMonth = 2 & IsPinYear ($ (pre + "Year"). value ))
{
N ++;
}
WriteDay (n, pre );
}
Function changeMonth (str, isstart)
{
Var pre = "start ";
If (isstart = false)
{
Pre = "end ";
}
Var year = $ (pre + "Year"). value;
If (year = "")
{
Var e = $ (pre + "Day ");
OptionClear (e );
Return;
}
Var n = MonHead [str-1];
If (str = 2 & IsPinYear ($ (pre + "Year ")))
{
N ++;
}
WriteDay (n, pre );
}
Function dateStart ()
{
Var defastarstarty = "2011 ";
Var defastarstartm = "1 ";
Var defastarstartd = "14 ";
Var defaultEndY = "2011 ";
Var defaultEndM = "2 ";
Var defaendendd = "23 ";
MonHead = [, 31,];
Var prestr = new Array ("start", "end ");
For (var j = 0; j <2; j ++)
{
Var pre = prestr [j];
// Start year
Var y = new Date (). getFullYear ();
If (pre = "start ")
{
// 10th days before start
Var I _index = 0;
For (var I = (y-10); I <= y; I ++)
{
$ (Pre + "Year"). options. add (new Option ("" + I + "", I ));
If (I = defaultStartY)
{
$ (Pre + "Year"). options [I _index]. selected = true;
}
I _index ++;
}
}
Else
{
Var I _index = 0;
For (var I = (y-5); I <= y + 5; I ++)
{
$ (Pre + "Year"). options. add (new Option ("" + I + "", I ));
If (I = defaultEndY)
{
$ (Pre + "Year"). options [I _index]. selected = true;
}
I _index ++;
}
}
// Start month
DefaultM = (pre = "start "? DefaultStartM: defaultEndM)
For (var I = 1; I <13; I ++)
{
$ (Pre + "Month"). options. add (new Option ("" + I + "", I ));
If (I = defaultM)
{
$ (Pre + "Month"). options [I-1]. selected = true;
}
}
// Start day
Var n = MonHead [$ (pre + "Month"). value];
If (new Date (). getMonth = 1 & IsPinYear ($ (pre + "Year"). value ))
{
N ++;
}
DefaultD = (pre = "start "? DefaultStartD: defaendendd)
WriteDay (n, pre );
$ (Pre + "Day"). options [defaultD-1]. selected = true;
}
}
Function writeDay (n, pre)
{
Var e = $ (pre + "Day ");
OptionClear (e );
For (var I = 1; I <(n + 1); I ++)
{
E. options. add (new Option ("" + I + "", I ));
}
}
Function IsPinYear (year)
{
Return (0 = year % 4 & (year % 100! = 0 | year % 4 = 0 ));
}
Function optionClear (e)
{
For (var I = e. options. length; I> = 0; I --)
{
E. remove (I );
}
}
</Script>
</Head>
<Body onload = "dateStart ()">
<P name = "selectdate">
Slave
<Select id = "startYear" name = "startYear" onchange = "changeYear (this. value, true)">
</Select>
Year
<Select id = "startMonth" name = "startMonth" onchange = "changeMonth (this. value, true)">
</Select>
Month
<Select id = "startDay" name = "startDay">
</Select>
Day
To
<Select id = "endYear" name = "endYear" onchange = "changeYear (this. value, false)">
</Select>
Year
<Select id = "endMonth" name = "endMonth" onchange = "changeMonth (this. value, false)">
</Select>
Month
<Select id = "endDay" name = "endDay">
</Select>
Day
</P>
</Body>
I have referenced some code and hope to help some friends who need it.