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 相关文章推荐
解放web程序员的输入验证
Oct 06 Javascript
Javascript - HTML的request类
Jan 09 Javascript
Jquery 跨域访问 Lightswitch OData Service的方法
Sep 11 Javascript
解析javascript瀑布流原理实现图片滚动加载
Mar 10 Javascript
浅谈jQuery animate easing的具体使用方法(推荐)
Jun 17 Javascript
js求数组中全部数字可拼接出的最大整数示例代码
Aug 25 Javascript
Vue-router结合transition实现app前进后退动画切换效果的实例
Oct 11 Javascript
浅谈vue父子组件怎么传值
Jul 21 Javascript
微信小程序textarea层级过高的解决方法
Mar 04 Javascript
详解钉钉小程序组件之自定义模态框(弹窗封装实现)
Mar 07 Javascript
javascript 易错知识点实例小结
Apr 25 Javascript
Nest.js散列与加密实例详解
Feb 24 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写的基于Memcache的Queue实现代码
2011/11/27 PHP
第四章 php数学运算
2011/12/30 PHP
对于PHP 5.4 你必须要知道的
2013/08/07 PHP
php检测网页是否被百度收录的函数代码
2013/10/09 PHP
php发送get、post请求的6种方法简明总结
2014/07/08 PHP
php性能分析之php-fpm慢执行日志slow log用法浅析
2016/10/17 PHP
论坛特效代码收集(落伍转发-不错)
2006/12/02 Javascript
Javascript YUI 读码日记之 YAHOO.util.Dom - Part.3
2008/03/22 Javascript
JavaScript获取网页表单action属性的方法
2015/04/02 Javascript
JS+CSS实现分类动态选择及移动功能效果代码
2015/10/19 Javascript
AngularJS中的$watch(),$digest()和$apply()区分
2016/04/04 Javascript
详解JavaScript中|单竖杠运算符的使用方法
2016/05/23 Javascript
webpack实现热加载自动刷新的方法
2017/07/30 Javascript
vue组件传递对象中实现单向绑定的示例
2018/02/28 Javascript
微信小程序日历组件使用方法详解
2018/12/29 Javascript
了解JavaScript函数中的默认参数
2019/05/30 Javascript
Vue 数据响应式相关总结
2021/01/28 Vue.js
[01:01:52]完美世界DOTA2联赛PWL S2 GXR vs Magma 第二场 11.25
2020/11/26 DOTA
Python3.x版本中新的字符串格式化方法
2015/04/24 Python
浅谈Python中的闭包
2015/07/08 Python
python安装cx_Oracle模块常见问题与解决方法
2017/02/21 Python
python numpy 一维数组转变为多维数组的实例
2018/07/02 Python
如何用Python破解wifi密码过程详解
2019/07/12 Python
Python数据可视化:箱线图多种库画法
2019/11/06 Python
HTML5制作酷炫音频播放器插件图文教程
2014/12/30 HTML / CSS
英国领先的狗和宠物美容专家:Christies Direct
2017/04/03 全球购物
本科生详细的自我评价
2013/09/19 职场文书
法律专业学生的自我评价
2014/02/07 职场文书
幼儿园中班下学期评语
2014/04/18 职场文书
小学课外活动总结
2014/07/09 职场文书
商品陈列协议书
2014/09/29 职场文书
大学生考试作弊检讨书1000字
2014/10/14 职场文书
工作简报怎么写
2015/07/21 职场文书
2016党员读书思廉心得体会
2016/01/23 职场文书
python开发的自动化运维工具ansible详解
2021/08/07 Python
JS数组方法some、every和find的使用详情
2021/10/05 Javascript