<% @ Page Language = "Java" Import = "Java. util. *" pageencoding = "UTF-8" %>
<%
Request. setcharacterencoding ("UTF-8 ");
Response. setcharacterencoding ("UTF-8 ");
String Path = request. getcontextpath ();
String basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/";
%>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Base href = "<% = basepath %>">
<Title> my JSP 'date. jsp 'starting page </title>
<Meta http-equiv = "Pragma" content = "no-Cache">
<Meta http-equiv = "cache-control" content = "no-Cache">
<Meta http-equiv = "expires" content = "0">
<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "Description" content = "this is my page">
<! --
<LINK rel = "stylesheet" type = "text/CSS" href = "styles.css">
-->
<SCRIPT type = "text/JavaScript" src = "jquery/jquery-1.8.0.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
// Obtain the year
Function getyear (){
// Get the drop-down list
VaR year = $ ("# year ");
// Instantiate the date object
VaR date = new date ();
// Cyclically add
For (VAR I = date. getfullyear (); I> = 1990; I --){
// $ ("<Option>") is <option> </option>
// Val (I). Text (I) is <option value = '+ I +'> I </option>
// Last year. append drop-down option
Year. append ($ ("<option>"). Val (I). Text (I ));
}
}
// Obtain the month
Function getmonth (){
// Month drop-down list
VaR month = $ ("# month ");
For (VAR I = 1; I <= 12; I ++ ){
Month. append ($ ("<option>"). Val (I). Text (I ));
}
}
// Obtain the number of days
Function getdate (){
VaR yearval = $ ("# year"). Val ();
VaR monthval = $ ("# month"). Val ();
VaR day = $ ("# date ");
// Clear
Day. Empty ();
// Set the date function. The value 0 is used to obtain the maximum number of days in the current month.
// If the value of date is set to 0, the result is the last day of the previous month. The values are automatically calculated for the year of the current month and the year of the current month.
// If date is set to 1, the first day of the next month is obtained.
// The reason is that monthval obtains the correct month, and the month obtained through date is 0-11.
// In this case, new date (yearval, monthval, 0); sets the initial date of the next month.
VaR date = new date (yearval, monthval, 0 );
For (VAR I = 1; I <= date. getdate (); I ++ ){
Day. append ($ ("<option>"). Val (I). Text (I ));
}
}
// Add a value to the drop-down list
Function showdate (){
Getyear ();
Getmonth ();
Getdate ();
}
</SCRIPT>
</Head>
<Body onload = "showdate ()">
Year: <select id = "year" onchange = "getdate ()"> </SELECT>
Month: <select id = "month" onchange = "getdate ()"> </SELECT>
Day: <select id = "date" onchange = "getdate ()"> </SELECT>
</Body>
</Html>
Date: Add a date to the drop-down list and optimize it. Currently, the best solution on my blog is to get a year-on-year jump through judgment, which allows the system to automatically judge, code example without if judgment