zoukankan      html  css  js  c++  java
  • 三级联动日期选择

    <!DOCTYPE html>
    <html>
    
        <head>
            <meta charset="UTF-8">
            <title></title>
        </head>
    
        <body>
            <select id="year"></select><select id="month"></select><select id="day"></select></body>
    
    </html>
    <script>
        var year = document.getElementById("year");
        var month = document.getElementById("month");
        var day = document.getElementById("day");
    
        var time = new Date();
        year_now = time.getFullYear();
    
        for(var i = year_now - 100; i < year_now + 100; i++) {
            year.innerHTML += "<option>" + i + "</option>"
        }
        for(var i = 1; i < 13; i++) {
            month.innerHTML += "<option>" + i + "</option>";
        }
    
        function days(max) {
            day.innerHTML = "";
            for(var i = 1; i <= max; i++) {
                day.innerHTML += "<option value='"+i+"'>" + i + "</option>";
            }
        }
        
        year.onchange = function(){
            if( month.selectedOptions[0].innerHTML==1   ||
                month.selectedOptions[0].innerHTML==3   ||
                month.selectedOptions[0].innerHTML==5   ||
                month.selectedOptions[0].innerHTML==7   ||
                month.selectedOptions[0].innerHTML==8   ||
                month.selectedOptions[0].innerHTML==10  ||
                month.selectedOptions[0].innerHTML==12 
            ){
                days(31);
            }else if(
                month.selectedOptions[0].innerHTML==4   ||
                month.selectedOptions[0].innerHTML==6   ||
                month.selectedOptions[0].innerHTML==9   ||
                month.selectedOptions[0].innerHTML==11  
            ){
                days(30);
            }else{
                var year_selected = year.selectedOptions[0].innerHTML;
                if((year_selected%4==0&&year_selected%100!=0)||year_selected%400==0){
                    days(29);
                }else{
                    days(28);
                }
            }
        }
        month.onchange = function(){
            if( month.selectedOptions[0].innerHTML==1   ||
                month.selectedOptions[0].innerHTML==3   ||
                month.selectedOptions[0].innerHTML==5   ||
                month.selectedOptions[0].innerHTML==7   ||
                month.selectedOptions[0].innerHTML==8   ||
                month.selectedOptions[0].innerHTML==10  ||
                month.selectedOptions[0].innerHTML==12 
            ){
                days(31);
            }else if(
                month.selectedOptions[0].innerHTML==4   ||
                month.selectedOptions[0].innerHTML==6   ||
                month.selectedOptions[0].innerHTML==9   ||
                month.selectedOptions[0].innerHTML==11  
            ){
                days(30);
            }else{
                var year_selected = year.selectedOptions[0].innerHTML;
                if((year_selected%4==0&&year_selected%100!=0)||year_selected%400==0){
                    days(29);
                }else{
                    days(28);
                }
            }
        }
    </script>
  • 相关阅读:
    数据库my.ini配置
    子查询|视图|事务
    AspCms标签。链接地址:http://biaoqian.iasp.com.cn/
    c#代码实现百度搜索页面网页遍历
    DataTable 应用以及 dataGridView的用法参考代码
    c#语言报表和图表。
    C# 网络编程之webBrowser获取网页url和下载网页中图片
    C#语言实现对网页图片的随机抓取。基础办法,但还有一点小问题,欢迎大家指正
    c#语言实现对电脑文件夹的批量改名,选定改名
    c#邮件群发
  • 原文地址:https://www.cnblogs.com/yangchuanqi/p/7613249.html
Copyright © 2011-2022 走看看