热门标签 | HotTags
当前位置:  开发笔记 > 前端 > 正文

js日期、星座的级联显示代码

本篇文章主要是对js日期、星座的级联显示代码进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助

js 代码

代码如下:

    function birthdayOnchange(obj) {
        var year = $("<%= DDL_Year.ClientID%>").value;

        if (year == "year")
            return;
        else
            year = parseInt(year, 10);


        var mOnth= $("<%=DDL_Month.ClientID%>").value;
        if (mOnth== "month")
            return;
        else
            mOnth= parseInt(month, 10);

        var day = $("<%=DDL_Day.ClientID%>").value;
        var wholeday = getDays(year, month);

        if (1) {
            var optiOns= $("<%=DDL_Day.ClientID%>").options;
            for (var i = 1; i <= wholeday; i++) {
                var j = i.toString();
                j = j.length == 1 ? "0" + j : j;
                options.length = i + 1;
                options[i].value = j;
                options[i].text = j;
                if (day <= wholeday && i == day) {
                    options[i].selected = true;
                }
            }
        }
    }

 function getDays(year, month) {
        var dayarr = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

        if (mOnth== 2) {
            if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0 || year <1900)
                return 29;
            else
                return dayarr[month - 1];
        }
        else {
            return dayarr[month - 1];
        }
    }

    function adjustAstro() {
        var v_astro = getAstro($("<%=DDL_Month.ClientID%>").value, $("<%=DDL_Day.ClientID%>").value);
        $("<%=astro.ClientID %>").options[0].text = v_astro;
    }

    function getAstro(v_month, v_day) {
        v_mOnth= parseInt(v_month, 10)
        v_day = parseInt(v_day, 10);

        if ((v_mOnth== 12 && v_day >= 22)
  || (v_mOnth== 1 && v_day <= 20)) {
            return "魔羯座";
        }
        else if ((v_mOnth== 1 && v_day >= 21)
  || (v_mOnth== 2 && v_day <= 19)) {
            return "水瓶座";
        }
        else if ((v_mOnth== 2 && v_day >= 20)
  || (v_mOnth== 3 && v_day <= 20)) {
            return "双鱼座";
        }
        else if ((v_mOnth== 3 && v_day >= 21)
  || (v_mOnth== 4 && v_day <= 20)) {
            return "白羊座";
        }
        else if ((v_mOnth== 4 && v_day >= 21)
  || (v_mOnth== 5 && v_day <= 21)) {
            return "金牛座";
        }
        else if ((v_mOnth== 5 && v_day >= 22)
  || (v_mOnth== 6 && v_day <= 21)) {
            return "双子座";
        }
        else if ((v_mOnth== 6 && v_day >= 22)
  || (v_mOnth== 7 && v_day <= 22)) {
            return "巨蟹座";
        }
        else if ((v_mOnth== 7 && v_day >= 23)
  || (v_mOnth== 8 && v_day <= 23)) {
            return "狮子座";
        }
        else if ((v_mOnth== 8 && v_day >= 24)
  || (v_mOnth== 9 && v_day <= 23)) {
            return "处女座";
        }
        else if ((v_mOnth== 9 && v_day >= 24)
  || (v_mOnth== 10 && v_day <= 23)) {
            return "天秤座";
        }
        else if ((v_mOnth== 10 && v_day >= 24)
  || (v_mOnth== 11 && v_day <= 22)) {
            return "天蝎座";
        }
        else if ((v_mOnth== 11 && v_day >= 23)
  || (v_mOnth== 12 && v_day <= 21)) {
            return "射手座";
        }
        return "";
    }


html
代码如下:

               
出生日期:

               

                   
                   
                   
               

               

星座:

               

                   
               


推荐阅读
author-avatar
书友23295799
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有