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

  • 相关阅读:
    RAW和JPEG的区别_ZT
    用户自定义基元UDP_ZT
    UDP用户自定义原语
    SR锁存器
    Matlab实现Butterworth滤波器 分类: 图像处理 2014-06-02 00:05 527人阅读 评论(0) 收藏
    egrep命令的实现 分类: 编译原理 2014-06-01 23:41 329人阅读 评论(0) 收藏
    随机L系统分形树 分类: 计算机图形学 2014-06-01 23:27 376人阅读 评论(0) 收藏
    matlab实现算术编解码 分类: 图像处理 2014-06-01 23:01 357人阅读 评论(0) 收藏
    命名管道实现进程间通信--石头、剪刀、布游戏 分类: linux 2014-06-01 22:50 467人阅读 评论(0) 收藏
    互斥锁与条件变量应用 2014-06-01 22:20 328人阅读 评论(0) 收藏
  • 原文地址:https://www.cnblogs.com/webqiand/p/4609732.html
Copyright © 2011-2022 走看看