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 相关文章推荐
一个级联菜单代码学习及removeClass与addClass的应用
Jan 24 Javascript
jQuery ajax serialize() 方法使用示例
Nov 02 Javascript
node.js中的fs.appendFile方法使用说明
Dec 17 Javascript
jQuery中width()方法用法实例
Dec 24 Javascript
详述JavaScript实现继承的几种方式(推荐)
Mar 22 Javascript
AngularJS 自定义指令详解及示例代码
Aug 17 Javascript
javascript性能优化之分时函数的介绍
Mar 28 Javascript
深入理解JavaScript 中的匿名函数((function() {})();)与变量的作用域
Aug 28 Javascript
vue.js引入外部CSS样式和外部JS文件的方法
Jan 06 Javascript
详解原生JS回到顶部
Mar 25 Javascript
详解小程序退出页面时清除定时器
Apr 28 Javascript
微信小程序实现上拉加载功能示例【加载更多数据/触底加载/点击加载更多数据】
May 29 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制作静态网站的模板框架(一)
2006/10/09 PHP
我的论坛源代码(六)
2006/10/09 PHP
php array_intersect比array_diff快(附详细的使用说明)
2011/07/03 PHP
PHP中使用localhost连接Mysql不成功的解决方法
2014/08/20 PHP
php查询mysql数据库并将结果保存到数组的方法
2015/03/18 PHP
深入探究PHP的多进程编程方法
2015/08/18 PHP
php文件缓存方法总结
2016/03/16 PHP
php过滤htmlspecialchars() 函数实现把预定义的字符转换为 HTML 实体用法分析
2019/06/25 PHP
$.ajax json数据传递方法
2008/11/19 Javascript
JQuery 无废话系列教程(二) jquery实战篇上
2009/06/23 Javascript
解决JQeury显示内容没有边距内容紧挨着浏览器边线
2013/12/20 Javascript
使用Node.js配合Nginx实现高负载网络
2015/06/28 Javascript
使用Xcache缓存器加速PHP网站的配置方法
2017/04/22 Javascript
手把手教你搭建ES6的开发运行环境
2017/07/11 Javascript
jQuery图片查看插件Magnify开发详解
2017/12/25 jQuery
jQuery实现炫丽的3d旋转星空效果
2018/07/04 jQuery
node.js使用express框架进行文件上传详解
2019/03/03 Javascript
Vue可自定义tab组件用法实例
2019/10/24 Javascript
Python实现的检测web服务器健康状况的小程序
2014/09/17 Python
python实现简单tftp(基于udp协议)
2018/07/30 Python
python模块导入的细节详解
2018/12/10 Python
Python 循环终止语句的三种方法小结
2019/06/24 Python
python 读取修改pcap包的例子
2019/07/23 Python
Python-split()函数实例用法讲解
2020/12/18 Python
英国最大的汽车配件在线商店:Euro Car Parts
2019/09/30 全球购物
美国浴缸、水槽和水龙头购物网站:Vintage Tub & Bath
2019/11/05 全球购物
泰国第一在线超市:Tops
2021/02/13 全球购物
请描述一下”is a”关系和”has a”关系
2015/02/03 面试题
阿里巴巴的Oracle DBA笔试题答案-SQL tuning类
2016/04/03 面试题
民政局副局长民主生活会个人对照检查材料
2014/09/19 职场文书
2014党委书记四风对照检查材料思想汇报
2014/09/21 职场文书
作风整顿个人剖析材料
2014/10/06 职场文书
2014企业年终工作总结
2014/12/23 职场文书
2016年小学生寒假总结
2015/10/10 职场文书
2016高考寄语或鼓励的话语
2015/12/04 职场文书
商业计划书之服装
2019/09/09 职场文书