zoukankan      html  css  js  c++  java
  • 年月日下拉联动代码

    这是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下,就可以了。

  • 相关阅读:
    Mysql升级过程的问题
    关于SSM项目注解事务不回滚的问题
    Linux环境下tomcat如何热部署
    Windows系统下python3中安装pyMysql
    jvm性能监控及故障处理工具(《深入理解java虚拟机》)
    jvm垃圾回收器(《深入理解java虚拟机》)
    jvm-运行时数据区域(《深入理解java虚拟机》)
    java源码分析-String
    java源码分析-Object
    2019秋季PAT甲级题解(无第一题)
  • 原文地址:https://www.cnblogs.com/webqiand/p/4609732.html
Copyright © 2011-2022 走看看