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


Posted in Javascript onJanuary 23, 2014

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
                <DIV>出生日期:</DIV>
                <DIV>
                    <asp:DropDownList ID="DDL_Year" runat="server"  onchange="birthdayOnchange(this);"></asp:DropDownList> 年 
                    <asp:DropDownList ID="DDL_Month" runat="server"  onchange="birthdayOnchange(this);adjustAstro();"></asp:DropDownList> 月 
                    <asp:DropDownList ID="DDL_Day" runat="server" onchange="adjustAstro();"></asp:DropDownList> 日 
                </DIV>
                <DIV>星座:</DIV>
                <DIV>
                    <SELECT id=astro disabled name=astro runat="server"> 
                        <OPTION selected>处女座</OPTION>
                    </SELECT>
                </DIV>
Javascript 相关文章推荐
JavaScript replace(rgExp,fn)正则替换的用法
Mar 04 Javascript
再次分享18个非常棒的jQuery表格插件
Apr 10 Javascript
日历查询的算法 如何计算某一天是星期几
Dec 12 Javascript
js判断屏幕分辨率的代码
Jul 16 Javascript
JS实现定时页面弹出类似QQ新闻的提示框
Nov 07 Javascript
javascript计时器详解
Feb 28 Javascript
javascript验证身份证号
Mar 03 Javascript
纯js实现重发验证码按钮倒数功能
Apr 21 Javascript
使用微信内嵌H5网页解决JS倒计时失效问题
Jan 13 Javascript
Ionic3 UI组件之autocomplete详解
Jun 08 Javascript
JS实现移动端按首字母检索城市列表附源码下载
Jul 05 Javascript
零基础之Node.js搭建API服务器的详解
Mar 08 Javascript
js根据日期判断星座的示例代码
Jan 23 #Javascript
jQuery中Dom的基本操作小结
Jan 23 #Javascript
利用js正则表达式验证手机号,email地址,邮政编码
Jan 23 #Javascript
js验证电话号码与手机支持+86的正则表达式
Jan 23 #Javascript
Jquery 过滤器(first,last,not,even,odd)的使用
Jan 22 #Javascript
Jquery遍历节点的方法小集
Jan 22 #Javascript
Jquery如何实现点击时高亮显示代码
Jan 22 #Javascript
You might like
php_xmlhttp 乱码问题解决方法
2009/08/07 PHP
在wamp集成环境下升级php版本(实现方法)
2013/07/01 PHP
JavaScript 操作键盘的Enter事件(键盘任何事件),兼容多浏览器
2010/10/11 Javascript
javascript 弹出窗口中是否显示地址栏的实现代码
2011/04/14 Javascript
基于jquery实现的移入页面上空文本框时,让它变为焦点,移出清除焦点
2011/07/26 Javascript
分享20多个很棒的jQuery 文件上传插件或教程
2011/09/04 Javascript
dwz 如何去掉ajaxloading具体代码
2013/05/22 Javascript
jquery.validate的使用说明介绍
2013/11/12 Javascript
jquery默认校验规则整理
2014/03/24 Javascript
最简单纯JavaScript实现Tab标签页切换的方式(推荐)
2016/07/25 Javascript
引入JavaScript时alert弹出框显示中文乱码问题
2017/09/16 Javascript
微信小程序 搜索框组件代码实例
2019/09/06 Javascript
[02:35]DOTA2英雄基础教程 狙击手
2014/01/14 DOTA
python在不同层级目录import模块的方法
2016/01/31 Python
python控制windows剪贴板,向剪贴板中写入图片的实例
2018/05/31 Python
python3 实现一行输入,空格隔开的示例
2018/11/14 Python
Python Django切换MySQL数据库实例详解
2019/07/16 Python
python通过txt文件批量安装依赖包的实现步骤
2019/08/13 Python
pandas和spark dataframe互相转换实例详解
2020/02/18 Python
python多线程semaphore实现线程数控制的示例
2020/08/10 Python
Pycharm 如何一键加引号的方法步骤
2021/02/05 Python
便携式太阳能系统的创新者:GOAL ZERO
2018/02/04 全球购物
德国高尔夫商店:Golfshop.de
2019/06/22 全球购物
为什么要优先使用同步代码块而不是同步方法?
2013/01/30 面试题
c/c++某大公司的两道笔试题
2014/02/02 面试题
Oracle快照(snapshot)
2015/03/13 面试题
物流专业大学生求职信范文
2013/10/28 职场文书
高校十八大报告感想
2014/01/27 职场文书
优秀社区干部事迹材料
2014/02/03 职场文书
考研英语复习计划
2015/01/19 职场文书
学校捐书倡议书
2015/04/27 职场文书
幼儿园保教工作总结2015
2015/10/15 职场文书
某学校的2019年度工作报告范本
2019/10/11 职场文书
PhpSpreadsheet中文文档 | Spreadsheet操作教程实例
2021/04/01 PHP
php7中停止php-fpm服务的方法详解
2021/05/09 PHP
MySQL EXPLAIN输出列的详细解释
2021/05/12 MySQL