这是JS的代码:
function getSDay(){ var year ; var month ; var maxday=0 ; with( document.sedate.syear ){ year = options[selectedIndex].text; } with( document.sedate.smonth ){ month = options[selectedIndex].text; } if( month==1 | month==3 | month==5 | month==7 | month==8 | month==10 | month==12 ){ maxday = 31 ; }else if( month==4 | month==6 | month==9 | month==11 ){ maxday = 30 ; }else if( month == 2 ){ if( (year%4==0 & year%100!=0) | year%400==0 ){ maxday = 29 ; }else{ maxday = 28 ; } } with( document.sedate.sday ){ length = maxday+1; options[0].text="--不限"; options[0].value="--不限"; for( var i=1;i<maxday+1;i++ ){ options[i].text=i; options[i].value=i; } } } function getEDay(){ var year ; var month ; var maxday=0 ; with( document.sedate.eyear ){ year = options[selectedIndex].text; } with( document.sedate.emonth ){ month = options[selectedIndex].text; } if( year!="--不限" ){ if( month==1 | month==3 | month==5 | month==7 | month==8 | month==10 | month==12 ){ maxday = 31 ; }else if( month==4 | month==6 | month==9 | month==11 ){ maxday = 30 ; }else if( month == 2 ){ if( (year%4==0 & year%100!=0) | year%400==0 ){ maxday = 29 ; }else{ maxday = 28 ; } } } with( document.sedate.eday ){ length = maxday+1; options[0].text="--不限"; options[0].value="--不限"; for( var i=1;i<maxday+1;i++ ){ options[i].text=i; options[i].value=i; } } } 这是JSP的代码: <%@ page language="java" import="java.util.*" pageEncoding="GBK"%> <% 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 language="javascript" src="MyJavaScript/date.js" ></script> </head> <body> <form action="" name="sedate"> <table border="1" width="1000" align="center" > <tr> <td> 选择时间: </td> <td> <select name="syear" onchange="getSDay()" > <option selected>--不限</option> <% for( int i=0;i<30;i++ ){ %> <option><%=1990+i%></option> <% }%> </select> </td> <td> 年 </td> <td> <select name="smonth" onchange="getSDay()"> <option selected>--不限</option> <% for( int i=1;i<13;i++ ){ %> <option ><%=i%></option> <% }%> </select> </td> <td> 月 </td> <td> <select name="sday" > <option selected>--不限</option> </select> </td> <td> 日 </td> <td> 至 </td> <td> <select name="eyear" onchange="getEDay()"> <option selected>--不限</option> <% for( int i=0;i<30;i++ ){ %> <option><%=1990+i%></option> <% }%> </select> </td> <td> 年 </td> <td> <select name="emonth" onchange="getEDay()"> <option selected>--不限</option> <% for( int i=1;i<13;i++ ){ %> <option ><%=i%></option> <% }%> </select> </td> <td> 月 </td> <td> <select name="eday"> <option selected>--不限</option> </select> </td> <td> 日 </td> </tr> </table> </form> </body> </html>
在WEBROOT下建个文件夹MyJavaScript,把JS放进去,然后把文件夹和JS放WEBROT下,就可以了。